Reputation: 59
I'm trying to publish web site on IIS at Windows Server 2008 R2. my web site has a feature which download an excel file to apply some edits then upload it again. When access the excel file to be downloaded I got this error: "Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified."
Code which get File:
clsExcel = new ApplicationClass();
clsExcel.Visible = false;
clsWorkbook = clsExcel.Workbooks.Open(Server.MapPath("/file path ... "), 2, false, 5, "", "", true, XlPlatform.xlWindows, "", false, true, 0, false, true, XlCorruptLoad.xlNormalLoad);
// get worksheet 4 ...
clsWorksheet = (Worksheet)clsWorkbook.Worksheets[4];
clsWorksheet.get_Range("A2", "D1000").EntireRow.Delete();
clsWorkbook.Save();
clsWorkbook.Close(false, "", false);
// release...
clsExcel.Quit();
I'm sure that my code is well, because I'm running it on my personal PC which has Windows 10 OS with Office 2013 and it works perfectly. I think I miss some configuration or file which must be exist at the server.
After Days of search I found a lot of solutions but it is not working with me like: - Install Office 2010 - Customize Microsoft Excel Application in DCOM Config to allow access for IIS_User and NETWORK SERVICE - Add Microsoft.Office.Interop.Excel as a reference - Comment assembly line from web.config
What should I do?
Thanks in advance
Upvotes: 1
Views: 16075
Reputation: 83
1: Install Microsoft Office in Client Machine 2: Check Microsoft.Interop.Office.Excel for Error Version in present in your bin directory or not .
Upvotes: 0
Reputation: 59
Another way I found and after trying it it solved:
Upvotes: 0
Reputation: 13641
If you are not going to install Office 2013 on your web server then you will need to copy the libraries when you publish your web site. In your Visual Studio project you will need to set Copy Local to True for the Interop assemblies. That way when you publish your site the referenced libraries will be copied along with your site and referenced from the copied files.
Something else you might need to check is that Enable 32-bit Applications is set to True in your app pool.
Upvotes: 2