在asp.net web API中,如何创建一个下载示例.xlsx文件的功能?我尝试了下面的功能。
public HttpResponseMessage DownloadExcelFile()
{
string filePath = Directory.GetCurrentDirectory() + "/Modules/SampleFiles/sample3.xlsx";
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(filePath, FileMode.Open));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "sample3.xlsx"
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return response;
}
字符串
我试过下面的
public HttpResponseMessage DownloadExcelFile()
{
string filePath = Directory.GetCurrentDirectory() + "/Modules/SampleFiles/sample3.xlsx";
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(filePath, FileMode.Open));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "sample3.xlsx"
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return response;
}
型
1条答案
按热度按时间olqngx591#
你试过使用下面的MediaType吗?
字符串