Hi All,
I am exporting from gridview to excel format. But it is saving as web page. I manually need to save as microsoft excel workbook.Then only it is getting saved as excel. Is there any solution that can be applied to get saved as excel automatically.
Here is the code...
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Resource.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving then
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Please help me..