Search code examples
export-to-excel

Error occured while export data from excel


I am getting an error while exporting data to an excel sheet.

Code

Response.Clear()
Response.AddHeader("content-disposition",   "attachment;filename=CompletionDatesReport.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
gridData.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()

Error

Internet explorer cannot download abc.aspx from www.xyz.com.
Internet explorer was not able to open this internet site.The requested site is either unavailable or cannot be found.Please try again later.


Solution

  • Remove the line no 4

    Response.Cache.SetCacheability(HttpCacheability.NoCache)

    It will be work.