How to return file from ASP.net 5 web api
used IActionResult instead of HttpResponseMessage. And returned FileStreamResult, and got it working.
Got a new problem, the file is not the one I open with the stream from server. But will create a new question for that.
Continues : Return file from ASP.NET 5 Web API
Thanks
This is the "low-level" HTTP approach, which should work with both ASP.NET WebAPI or ASP.NET MVC.
[HttpGet]
public HttpResponseMessage Download()
{
var fs = new FileStream(myfileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, 32768, true);
var response = new HttpResponseMessage {
Content = new StreamContent(fs);
}
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;
}