1

In our code, there is an option to export metadata as an XML file. The code that does that is below:

string xml = ToXML(metadatas, files);

context.Response.AddHeader("Content-Type", "application/octet-stream");
context.Response.AddHeader("Content-Disposition", "attachment; filename=video_metadata.xml;");
context.Response.Write(xml);
context.Response.Flush();
context.Response.End();

This works just fine in Firefox. They click the button and are prompted to save the xml file. However, in Chrome, there is no save file prompt. Using fiddler, I can see that the xml data is all there in the response, and it has a status code of 200. There are no errors shown on my web server, and the client side shows no indication of error, either. It just doesn't recognize the data sent back as something to save into a file.

Any help would be much appreciated. On the same web server, we are able to successfully export csv files with the headers as such:

context.Response.AddHeader("Content-Type", "application/vnd.ms-excel");
context.Response.AddHeader("Content-Disposition", "attachment; filename=AssetList.csv;");

Edit: I tried both text/xml and application/xml, but unfortunately neither solved my problem.

  • +1 for `"Content-Disposition"` header, it made an Excel XML which was showing in browser to be downloaded. – Niloct Sep 03 '15 at 23:39

1 Answers1

0

I would definitely change your content type to "text/xml". With "application/octet-stream", you are specifying a binary file.. which I guess technically is correct. All files are binary, but in your case.. you probably want "text/xml".

Slack Shot
  • 1,090
  • 6
  • 10
  • Thanks, I tried both `text/xml` and `application/xml`, but unfortunately neither solved my problem. – Ryan Coonan Aug 29 '13 at 21:16
  • You also need to add the content-length header. http://stackoverflow.com/questions/11475981/chrome-not-displaying-pdf-from-asp-net-page – Slack Shot Aug 29 '13 at 21:34
  • Also, I'd try a "context.ApplicationInstance.CompleteRequest();" In place of the context.Response.End(); An end, can basically tell the browser that your download was interrupted.. versus a request complete.. telling it that you've given it the content for the request. – Slack Shot Aug 29 '13 at 23:02
  • I have tried all of your suggestions now, in various combinations. None have solved the problem, unfortunately. – Ryan Coonan Aug 30 '13 at 16:14
  • Try context.Response.WriteFile(xml); Feel really stupid now, but that should definitely work. Sorry. – Slack Shot Aug 30 '13 at 17:34