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

后端 未结 9 627
灰色年华
灰色年华 2020-12-02 06:11

In my ApiController class, I have following method to download a file created by server.

public HttpResponseMessage Get(int id)
{
    try
    {
        strin         


        
9条回答
  •  醉酒成梦
    2020-12-02 06:49

    You need to add the content-disposition header to the response:

     response.StatusCode = HttpStatusCode.OK;
     response.Content = new StreamContent(result);
     response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
     return response;
    

提交回复
热议问题