Unable to download excel file extracted from our application

Hi all,

We have a web application hosted on gearhost.com the idea is for our viewer to click a button to generate data from MSSQL server and download it in excel file prior to the hosting it is working fine but after the hosting, when we click the button it display the following error

Could not load file or assembly ‘Microsoft.Office.Interop.Excel, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

and we have a module in the application that send the excel file into stream save it before it will download the stream file bellow is the code section

string PathsTo = directoryPath +drpProgramArea.SelectedItem.Text.Trim()+"-"+drpYears.SelectedItem.Text.Trim()+"-"+drpYears2.SelectedItem.Text + “.xls”;

        //============ Download Excel file =====================

        Response.Buffer = true;
        Response.Charset = "";
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("content-disposition", "attachment;filename=" + PathsTo);
        using (MemoryStream MyMemoryStream = new MemoryStream())

we will appreciate any suggestion to the challenge

thank you all

Well i think you need to find that dll on your computer and upload it into your bin application bin folder.

I use this to generate excel files on the server:

The error you’re seeing is not an issue with the download of the file, it’s an issue with the creation of the Excel file. IT looks like you’re referencing the Excel dll when creating your Excel file. The DLL is part of MS Office and is present is your development environment because you have Office installed on the development machine. The DLL is not part of your solution.

The server that’s hosting your site does not have Office installed on it, so when your code tries to build the Excel file, it cannot find the Excel dll and throws the error you are seeing.

You have two options: 1) as hrvoje suggested, you can find the DLL and add it to your project so that it is available on the server. I’m not sure if licensing permits that type of use. You’d have to investigate that. 2) use a library to create your Excel file, like OpenXML, EPPlus.