例如,访问wwwroot下的files/file.pdf

ASP.NET Core访问wwwroot下的文件

    public class SendEmailController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        private IWebHostEnvironment _hostEnvironment;
        public SendEmailController(IWebHostEnvironment hostEnvironment)
        {
            _hostEnvironment = hostEnvironment;
        }

        [HttpPost]
        public IActionResult Index(EmailModel model)
        {
            // get the file path
            string fileName = Path.Combine(_hostEnvironment.WebRootPath, "files", "file.pdf");

            // code omitted
return View(); } }

IHostingEnvironment在未来的版本中将不再支持,所以建议使用IWebHostEnvironment。

相关文章:

  • 2021-09-23
  • 2021-12-16
  • 2022-02-16
  • 2022-12-23
  • 2021-10-27
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
相关资源
相似解决方案