Reputation: 51
System.IO.StringWriter objStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter);
gv.RenderControl(objHtmlTextWriter);
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=DemoExcel.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
Response.Output.Write(objStringWriter.ToString());
Response.Flush();
Response.Close();
giving error Response does not contain definition for ClearContent in Asp.net Core
Upvotes: 3
Views: 5902
Reputation: 721
Found this answer online https://forums.asp.net/t/1567637.aspx?Response+Clear+vs+Response+ClearContent+Response+ClearHeaders+
Response.Clear();
Response.Headers[HeaderNames.ContentDisposition] = "attachment; filename=DemoExcel.xls";
Response.WriteAsync(objStringWriter.ToString()).Wait()
Hopefully it helps someone
Upvotes: 6