I get an error
Invalid characters on the way
for the code below. Please help me.
response.Clear(); response.Charset = ""; Response.ContentEncoding = System.Text.Encoding.Default; // set the response mime type for excel response.ContentType = "application/vnd.ms-excel"; string sFileName = "Testeeeeee.xls"; response.AddHeader("Content-Disposition", "attachment;filename=\"" + sFileName + "\""); // 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); string sPath = @"E:\CR-12\Test.xls"; File.WriteAllText(sw.ToString(), sPath);// I get the error at this line response.End();
source share