0

I ran into this weird thing. Im trying to avoid adding the whole code as its long and kinda private but the issue is:

// string has no white spaces:

string fileName = "noWhiteSpacesHere" + ".pdf";
response.StatusCode = HttpStatusCode.OK;
response.Content = new ByteArrayContent(fileData);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") {FileName = fileName };

// ContentDispositionHeaderValue("attachment") = "noWhiteSpacesHere.pdf"

but in contrast:

// string has white spaces:

string fileName = "some white spaces" + ".pdf";
response.StatusCode = HttpStatusCode.OK;
response.Content = new ByteArrayContent(fileData);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") {FileName = fileName };

// ContentDispositionHeaderValue("attachment") = "\"some white spaces.pdf\""

**

  • note the extra quotation marks on the second example.
  • when i check the "fileName" parameter it does not show these extra quotation marks and they appear only in the content disposition header.
  • white spaces should be supported. i cant trim/replace etc.

**

i hope this is enough. do u guys know the reason? how can i stop this?

if any code is crucially missing let me know.

thanks!

  • This is, from my understanding, expected behaviour. Why is it an issue for you? – mjwills May 20 '20 at 07:40
  • Have you read https://stackoverflow.com/a/18634370/34092 and https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1 ? – mjwills May 20 '20 at 07:40
  • @mjwills this is an issue as some files have no whte spaces and some do. so some time i will send out extra quotation marks and some times not. i prefer it would b coherent – MC LinkTimeError May 20 '20 at 07:45
  • Did you read the spec? You see that is the expectation? The quotation marks _should be there_. Browsers will know how to handle it - so why does it matter? – mjwills May 20 '20 at 07:51
  • i saw it after u shared it. thanks! so - as i need one kind of beavior - should i add extra "" to string without white spaces? i need it to arrive to the browser side in one form (either with extra quotation marks for all or without extra quotations to all) – MC LinkTimeError May 20 '20 at 08:06
  • **Why** do you need this? Why does it matter to you? What _specifically_ is not working with your current code ("I don't like it" is not a reason)? – mjwills May 20 '20 at 23:04

0 Answers0