HttpResponse response problem???
hi i´m trying to use the code below to save a dataset in a excell format. But the response object is not recognized.
Anybody can help me...
Thanks
public void ConvertXLS(DataSet ds)
{
//first let's clean up the response.object
response.Clear();
response.Buffer = true;
response.Charset = "";
response.AddHeader("Content-Disposition", "attachment;filename=Report.xls");
//set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
//create a string writer
System.IO.StringWriter stringWrite;
stringWrite=new System.IO.StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite;
htmlWrite=new System.Web.UI.HtmlTextWriter(stringWrite);
//instantiate a datagrid
System.Web.UI.WebControls.DataGrid dg=new System.Web.UI.WebControls.DataGrid();
//set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables[0];
//bind the datagrid
dg.DataBind();
//tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite);
//all that's left is to output the html
response.Write(stringWrite.ToString());
response.End();
}
|