[英]Microsoft Office Excel cannot access the file on IIS
I have a web service method which search string in given Excel file and return its status.我有一个网络服务方法,它在给定的 Excel 文件中搜索字符串并返回其状态。 This is working okay in VS project.
这在 VS 项目中工作正常。 But when I public same web service in IIS its throwing error: I'm working on Windows7 machine
但是当我在 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);
I have checked filePath C:\\inetpub\\wwwroot\\MyFirstWebService\\App_Data\\Results.xlsx
and it is okay.我已经检查过
filePath C:\\inetpub\\wwwroot\\MyFirstWebService\\App_Data\\Results.xlsx
并且没问题。
I also tried with few online solutions like below, But its not fixed yet:我也尝试过像下面这样的几个在线解决方案,但它还没有修复:
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")
Why it's working on VS not on IIS?为什么它在 VS 上而不是在 IIS 上工作? my user account got admin right too, wonder why its not working.
我的用户帐户也获得了管理员权限,想知道为什么它不起作用。
Thanks谢谢
I was having issue while reading the Excel from MVC application hosted on IIS.我在从 IIS 上托管的 MVC 应用程序读取 Excel 时遇到问题。 Two things are important for accessing the Excel from IIS.
从 IIS 访问 Excel 有两件事很重要。
It`s kind of weired, not sure why this is required but worked for me.这有点奇怪,不知道为什么需要这样做,但对我有用。
I ran into this problem and couldn't find a solution anywhere. 我遇到了这个问题,在任何地方都找不到解决方案。 There were multiple issues at play here.
这里有多个问题。 The IIS application was on a 64 bit Windows server 2008 but the installed version of office was a 32 bit version.
IIS应用程序位于64位Windows Server 2008上,但Office的安装版本为32位版本。
This article pointed me in the right direction: 本文为我指出了正确的方向:
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 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
However, instead of security i had to change the identity of the Microsoft Excel Application in Dcom Config to be an administrator instead of the launching user. 但是,为了安全起见,我不得不将Dcom Config中Microsoft Excel应用程序的身份更改为管理员而不是启动用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.