I have a web service method which search string in given Excel file and return its status. This is working okay in VS project. But when I public same web service in IIS its throwing error: I'm working on Windows7 machine
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.
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? 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. Two things are important for accessing the Excel from IIS.
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.
This article pointed me in the right direction:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.