在我的ApiController类中,我有以下方法可以下载服务器创建的文件。
public HttpResponseMessage Get(int id)
{
try
{
string dir = HttpContext.Current.Server.MapPath("~"); //location of the template file
Stream file = new MemoryStream();
Stream result = _service.GetMyForm(id, dir, file);
if (result == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
result.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.Content = new StreamContent(result);
return response;
}
catch (IOException)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError);
}
}
除了默认的下载文件名是其ID外,其他所有东西都可以正常运行,因此用户可能每次必须在保存为对话框时键入自己的文件名。有什么方法可以在上面的代码中设置默认文件名?