public void ExportDataSetToExcel(DataSet ds, string filename) { HttpResponse response = HttpContext.Current.Response; // first let's clean up the response.object response.Clear(); response.Charset = ""; // set the response mime type for excel response.ContentType = "application/vnd.ms-excel"; response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\""); // create a string writer using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { // instantiate a datagrid DataGrid dg = new DataGrid(); dg.DataSource = ds.Tables[0]; dg.DataBind(); dg.RenderControl(htw); response.Write(sw.ToString()); response.End(); } } }
public override void VerifyRenderingInServerForm(System.Web.UI.Control control) { }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)