【发布时间】:2018-12-07 15:24:30
【问题描述】:
在我想下载此文件后,我将数据网格中的信息保存到文件夹中的 xslx 文件。 我有代码,工作正常,但是在我的项目中,当我尝试下载文件时,它什么也没返回。也许是因为保护或用户角色是管理员。 我尝试过使用不同的文件夹,我确信该文件夹不是问题。 还能是什么?
public FileResult downloadFile(string filePath)
{
IFileProvider provider = new PhysicalFileProvider(filePath);
IFileInfo fileInfo = provider.GetFileInfo(fileName);
var readStream = fileInfo.CreateReadStream();
var mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
return File(readStream, mimeType, fileName);
}
【问题讨论】:
-
你要向那个函数发送什么文件路径,请写一个例子
-
fileName = "SN-export.xlsx";字符串文件路径 = _hostingEnvironment.WebRootPath; string fileName2 = Path.Combine(filePath, fileName); FileInfo excelFile = new FileInfo(fileName2); if (excelFile.Exists) { excelFile.Delete(); excelFile = new FileInfo(fileName2); } excel.SaveAs(excelFile);返回下载文件(文件路径);
标签: excel asp.net-mvc download asp.net-core-2.0