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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With