Click here to Skip to main content
15,909,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Server has Microsoft Office 2003. Code is as below

at aspx Page

ASP.NET
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
  <ContentTemplate>
    <asp:LinkButton ID="ExportExcel" runat="server" OnClick="ExportTabletoExcel_Click" OnClientClick="ExportTableJqueryMethod">ExportExcel</asp:LinkButton>
 </ContentTemplate>
  <Triggers>
    <asp:PostBackTrigger ControlID="ExportExcel" />
  </Triggers>
</asp:UpdatePanel>


At Code behind

C#
using Excel1= Microsoft.Office.Interop.Excel;
...
protected void ExportTabletoExcel_Click(object sender, EventArgs e)
{
Excel1.Application excelApp = new Excel1.Application();
...//Adding Data to Excel
excelWorkBook.SaveAs(path, Excel1.XlFileFormat.xlWorkbookNormal);
excelWorkBook.Close();

...//to download
HttpContext.Current.Response.ContentType = "application/xls";
HttpContext.Current.Response.AppendHeader("content-disposition", "attachment; > filename=ExportedExcel.xls");
HttpContext.Current.Response.WriteFile(path + ".xls");
}


In Web.config

XML
<add assembly="Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/>


On click in Visual Studio the excel downloads just fine. But while running the same on server the refreshes the page and no excel downloads.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900