DEV Community

loading...

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

boyukbas profile image baris ・1 min read

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"
};

Discussion (0)

pic
Editor guide