I has binding the string Array into Datagrid, then I need to export the data to excel file by auto save the file in client machine. Below is the code i use.
string fileName = "attachment;filename= DetailReport.xlsx";
Response.Clear();
Response.AddHeader("content-disposition", fileName);
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
grdExcel.RenderControl(htmlWrite);
Response.Output.Write(stringWrite.ToString());
Response.Flush();
Response.End();
I success export the file and save in client machine but the content in the file include all the HTML tag, may I know what wrong to my code? Please Help!!