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")';
        });

 

posted @ 2022-04-26 14:55  派大没有星  阅读(221)  评论(0)    收藏  举报