我有一种Web服务方法,它在给定的Excel文件中搜索字符串并返回其状态。这在VS项目中工作正常。但是,当我在同一个公共网络服务IIS其投掷的错误:我正在Windows7的机器Microsoft Office Excel无法访问IIS上的文件
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组权限添加到Desktop文件夹,现在它正在工作。 – Ashok