KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have successfully implemented a Csv Media Type Formatter in my ASP.Net Web API project. I am able to get results back in Csv format. However the resulting filename is "parts" without an extension. Ideally, I want to be able to set this filename in the controller, but being able to add the extension globally would be a minimum. Below are the examples I have found Override OnGetResponseHeaders - I don't see that as an option in the current version. http://forums.asp.net/t/1782973.aspx/1?Setting+response+and+content+headers+esp+ContentDisposition+inside+a+MediaTypeFormatter According to that article this should work public override IEnumerable<KeyValuePair<string, string>> OnGetResponseHeaders(Type objectType, string mediaType, HttpResponseMessage responseMessage) { return new[] { new KeyValuePair<string, string>("Content-Disposition", "attachment; filename=testing.csv") }; } However Visual Studio says "There is no suitable method for override" and won't compile when I add that to my custom Csv Formatter. Return HttpMessageResponse from controller - How to set downloading file name in ASP.NET Web API However this appears to just be pushing existing server files, which would take the Csv serialization out of the mix. Below is an attempt to make this approach work: public HttpResponseMessage Get(string id) { var response = new HttpResponseMessage(); if (id == "test") { var data = GetTestData(); response.StatusCode = HttpStatusCode.OK; response.Content = new StreamContent(data); response.Content.Headers.ContentD
Tags (comma-separated)
Save Edits
Cancel