.netcore3.1 mvc 根据路径下载
程序员文章站
2023-12-30 15:12:16
...
根据路径下载
public IActionResult DownloadFile()
{
//string filePath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/") + model.Path;//"Excel/123.zip";//以字符流的形式下载文件
string filePath = Directory.GetCurrentDirectory().Replace("\\", "/") + "/wwwroot/modeulFile/模板下载.xls";
var addrUrl = filePath;
var stream = System.IO.File.OpenRead(addrUrl);
string fileExt = ".xls";//GetFileExt(file);
//获取文件的ContentType
var provider = new FileExtensionContentTypeProvider();
var memi = provider.Mappings[fileExt];
return File(stream, memi, Path.GetFileName("模板下载.xls"));
}