一、创建action
public class importController : BaseController { private IWebHostEnvironment _hostingEnvironment = null; public importController(IWebHostEnvironment hostingEnvironment ) { _hostingEnvironment = hostingEnvironment; } public IActionResult downLoadMuban() { string path = _hostingEnvironment.ContentRootPath + "/Up/muban.xls"; var stream = System.IO.File.OpenRead(path); string fileExt = System.IO.Path.GetExtension(path); //获取文件的ContentType var provider = new FileExtensionContentTypeProvider(); var memi = provider.Mappings[fileExt]; return File(stream, memi, Path.GetFileName(path)); } }
二、创建超链接
<a href="/import/downLoadMuban">模板</a>
完成!!
标签:core,asp,stream,hostingEnvironment,System,var,path,net,public From: https://www.cnblogs.com/sunzzhankui/p/16600720.html