DEV Community


Posted on


Answer: How to set downloading file name in ASP.NET Web API

You need to set the Content-Disposition header on the HttpResponseMessage:

HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.Content = new StreamContent(result);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    FileName = "foo.txt"

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<