Hi All, i want to export my LiteralControl of asp.net to excel workbook but m not able to do it as it is not opening a excel sheet to save but it is showing "Doumnet.aspx" file to save....here i'm giving the code of button click
protected void btnExport_excel_Click1(object sender, EventArgs e) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; // HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx"); HttpContext.Current.Response.Charset = ""; this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); ltATPCLP = (LiteralControl)(Session["exportData"]); ltATPCLP.RenderControl(hw);
string k = sw.ToString();
HttpContext.Current.Response.Write(k);
HttpContext.Current.Response.End(); }
|
any idea..... or any help please do it ASAP.
Thanks,
Amit