2015-06-21 94 views
0

我有一种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?我的用户帐户也有管理权,想知道为什么它不能正常工作。

感谢

+0

如果是在同一台机器,它有可能与权限,去IIS,看看哪些用户正在运行的应用程序池,不是试图以与FileInfo的打开文件,看看是否可以在所有 –

+0

访问文件将IIS_IUSRS组权限添加到Desktop文件夹,现在它正在工作。 – Ashok

回答

0

我遇到了这个问题,并不能在任何地方找到一个解决方案。这里有很多问题。 IIS应用程序位于64位Windows服务器2008上,但安装的Office版本是32位版本。

这篇文章我指出了正确的方向:

http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx

然而,除了安全,我不得不改变在DCOM配置Microsoft Excel应用程序的身份是管理员,而不是启动用户。