Samar ElFwakhry
Samar ElFwakhry

Reputation: 59

Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

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

Answers (3)

abhishek
abhishek

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

Samar ElFwakhry
Samar ElFwakhry

Reputation: 59

Another way I found and after trying it it solved:

  1. Install Office 2010 on your local PC.
  2. Add reference to your project from visual studio > COM > Microsoft office 14.0 Object Libaray.
  3. Build and Publish web site.
  4. Replace the old published folder with
    the new one.
  5. Make sure that your server has the same office version "2010" you installed on local PC.
  6. Finally, it works

Upvotes: 0

squillman
squillman

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

Related Questions