0

 oResponse.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName_DBText, Encoding.UTF8).Replace("+", "%20"));
 oResponse.AddHeader("Content-Disposition", "inline=" + HttpUtility.UrlEncode(fileName_DBText, Encoding.UTF8).Replace("+", "%20"));

The above was causing me an issue in Chrome only. No issue in IE or Firefox. Removal of the 2nd AddHeader (adding the inline directive), resolved the issue. I was under the impression that adding both was fine and the browser would work out what to do. Anyone have a definitive answer on this?

Terry Delahunt
  • 616
  • 4
  • 21

2 Answers2

2

a) no, you can't have multiple ones.

b) the syntax for the second one is invalid; "inline" doesn't take a parameter.

c) "inline" and "attachment" are contradictory; what are you trying to achieve?

(the spec is RFC 6266, btw)

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • I was mistaken in thinking you could specify the filename for downloaded files rendered in the browser and those where the user is prompted to open/save/save as, separately. I didn't realise it was either/or. – Terry Delahunt Apr 13 '16 at 09:03
  • Re. point A) we had a program allowing a user to click a link to view an attachment that had been uploaded. The prompt was asking them to save/save as/open a file whose name was made up of the aspx page and the uploaded file extension, so if the page was mypage.aspx & the file was .xls, it prompted them for mypage.xls, which was obv wrong. We wanted to display the real filename So using the content-disposition tag was the way to go, but I mistakenly thought I had to cater for the diff filetypes by using attachment AND inline. – Terry Delahunt Apr 13 '16 at 09:08
  • Re. point b), as an example, would the following be correct if using inline - response.Headers.Add("Content-Disposition", "inline; filename=myfile.xls"); – Terry Delahunt Apr 13 '16 at 09:08
0

Solution was very straightforward: Simply removed the following line of code -

oResponse.AddHeader("Content-Disposition", "inline=" + HttpUtility.UrlEncode(fileName_DBText, Encoding.UTF8).Replace("+", "%20"));

As @Julian Reschike stated, you cannot have multiple content-disposition headers, which I wasn't aware of. In any case, the syntax of the above line was incorrect as I had it. Line removed and everything back to how it should be.

Terry Delahunt
  • 616
  • 4
  • 21