1
Answer

Unable to download excel file extracted from our application

Hi,

I will be happy if you can help suggest solution to our problem, our site hosted is generating excel file when a visitor click the specific button, if that is done it generate the following 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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)".

i have use the excel.Application Visible ="False".

and i have directed the output to a stream for download

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

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

Response.Clear();
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())
{
xlWBK.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}

this is what i have tried.

any suggestion will be appreciated.
Answers (1)