asp.net - Download of xls working in IE/Firefox but named as aspx page in Chrome -
i'm having issue chrome renaming export file default of page name export being initiated from. i've gone through related forum posts find , have tried suggestions - i'm not seeing recent posts within past couple of years.
my code export (before modification attempts) follows:
public static void exporttospreadsheet(object items, string name) { httpresponse response = httpcontext.current.response; response.clear(); response.clearheaders(); response.charset = ""; response.contenttype = "application/vnd.ms-excel"; response.addheader("context-disposition", "attachment;filename=\"" + name + "\""); using (stringwriter sw = new stringwriter()) { using (system.web.ui.htmltextwriter htw = new system.web.ui.htmltextwriter(sw)) { system.web.ui.webcontrols.datagrid dg = new system.web.ui.webcontrols.datagrid(); dg.datasource = items; dg.databind(); dg.rendercontrol(htw); response.write(sw.tostring()); response.end(); } } }
the above code works flawlessly in ie/firefox. resulting result headers received (per chrome net-internals) is:
cache-control: private content-type: application/vnd.ms-excel server: microsoft-iis/8.0 context-disposition: attachment;filename="dataexport.xls" x-aspnet-version: 4.0.30319 x-sourcefiles: =?utf-8?b?qzpctxlfrgf0yvxbvfnnxerldjqwxhbvcnrhbfxdr0lfqxv0b21hdglvbl9gcmftzxdvcmtcqxv0b21hdglvbl9ezwnrlmfzchg=?= x-powered-by: asp.net date: fri, 05 dec 2014 19:37:05 gmt content-length: 86493
i've tried several updates includes hard coding filename "test.xls", clearing content of response, setting buffer true, setting cachecontrol , pragma no-cache, , overriding verifyrenderinginserverform() in page's code-behind. response headers after applying these changes follows:
cache-control: no-cache pragma: no-cache content-type: application/vnd.ms-excel expires: -1 server: microsoft-iis/8.0 context-disposition: attachment; filename="test.xls" x-aspnet-version: 4.0.30319 x-sourcefiles: =?utf-8?b?qzpctxlfrgf0yvxbvfnnxerldjqwxhbvcnrhbfxdr0lfqxv0b21hdglvbl9gcmftzxdvcmtcqxv0b21hdglvbl9ezwnrlmfzchg=?= x-powered-by: asp.net date: fri, 05 dec 2014 19:10:23 gmt content-length: 86493
this still produces same results chrome not recognizing/accepting filename , defaults pagename downloaded filename.
any recommendations how fix issue appreciated.
i'm using chrome version 39.0.2171.71 m
Comments
Post a Comment