C#中下载项目中的文件
1.将需要下载的文档添加到项目的文件夹中

2.接口部分
public IActionResult DownLoad() { var filePath = Directory.GetCurrentDirectory() + "\\UploadFileTemplate"; var strFileName = "Manual courier dispatch record upload.xlsx"; var strPath = filePath + @"\\" + strFileName; var stream = System.IO.File.OpenRead(strPath); return File(stream, "Application/x-msexcel", strFileName); }
3.前端部分
$("#Download").click(function () {
window.location.href =' @Url.Action("DownLoad", "MR")';
});

浙公网安备 33010602011771号