Reputation: 1619
i am trying to export an excel file from an https site, it is working great with firefox and other browsers but in IE its is giving me error that the site is not available or the file is not found.
i have research the problem and i have found it is cache related so i have change the headers in this page so it will allow caching but it is still not working.
this is a snap of the code
Response.Cache.SetAllowResponseInBrowserHistory(true);
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
Response.Cache.SetAllowResponseInBrowserHistory(true);
Response.CacheControl = "Public";
any help would be great thank you
Upvotes: 2
Views: 1531
Reputation: 4374
#region For Download to work on HTTPS
Response.ClearHeaders(); Response.Cache.SetCacheability(HttpCacheability.Private); Response.Buffer = true; Response.AddHeader("Content-Transfer-Encoding", "binary");
#endregion
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=Temp.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; StringWriter strWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(strWriter); string heading = "<h4 align='left'>Temp Excel Cube</h4>"; strWriter.Write(heading); gvTemp.RenderControl(htmlWrite); Response.Write(strWriter.ToString()); Response.End();
I guess this is what you are looking for. It works for me on HTTPS, I've exported a grid to an excel sheet, you can use it to pickup a file from a physical location too. :)
Upvotes: 1