【发布时间】:2015-06-21 13:41:21
【问题描述】:
我有一个 Web 服务方法,它在给定的 Excel 文件中搜索字符串并返回其状态。这在 VS 项目中工作正常。但是当我在 IIS 中公开相同的 Web 服务时,它会抛出错误:我正在使用 Windows7 机器
System.Runtime.InteropServices.COMException: Microsoft Office Excel cannot access the file 'C:\inetpub\wwwroot\MyFirstWebService\App_Data\Results.xlsx'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
string filePath = Server.MapPath("~") + @"\App_Data\Results.xlsx";
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(filePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
我检查了filePath C:\inetpub\wwwroot\MyFirstWebService\App_Data\Results.xlsx,没问题。
我也尝试过以下几种在线解决方案,但尚未修复:
Create directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or
"C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)
Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user
"IIS AppPool\DefaultAppPool")
为什么它在 VS 上运行而不在 IIS 上运行?我的用户帐户也获得了管理员权限,不知道为什么它不起作用。
谢谢
【问题讨论】:
-
如果是同一台机器,那得和权限有关,去IIS看看是哪个用户在运行应用程序池,然后用FileInfo打开文件看看能不能访问文件
-
向桌面文件夹添加了 IIS_IUSRS 组权限,现在可以使用了。
标签: c# asp.net excel web-services iis