diff --git a/QYZH.InteractiveMagazine.WebApi/Controllers/BaseController.cs b/QYZH.InteractiveMagazine.WebApi/Controllers/BaseController.cs index 100eaf0..0788b80 100644 --- a/QYZH.InteractiveMagazine.WebApi/Controllers/BaseController.cs +++ b/QYZH.InteractiveMagazine.WebApi/Controllers/BaseController.cs @@ -102,8 +102,12 @@ public abstract class BaseController : ControllerBase protected (string, string) DownloadImportTemplate(List list, string fileName) { IWebHostEnvironment webHostEnvironment = ServiceContext.GetService(); + var webRoot = webHostEnvironment.WebRootPath + ?? Path.Combine(webHostEnvironment.ContentRootPath, "wwwroot"); + if (!Directory.Exists(webRoot)) Directory.CreateDirectory(webRoot); + string sFileName = $"{fileName}.xlsx"; - string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", sFileName); + string fullPath = Path.Combine(webRoot, "ImportTemplate", sFileName); //不存在模板创建模板 if (!Directory.Exists(fullPath)) @@ -124,8 +128,12 @@ public abstract class BaseController : ControllerBase protected (string, string) ExportExcelMini(List list, string sheetName, string fileName) { IWebHostEnvironment webHostEnvironment = ServiceContext.GetService(); + var webRoot = webHostEnvironment.WebRootPath + ?? Path.Combine(webHostEnvironment.ContentRootPath, "wwwroot"); + if (!Directory.Exists(webRoot)) Directory.CreateDirectory(webRoot); + string sFileName = $"{fileName}_{DateTime.Now:MMdd_HHmmss}.xlsx"; - string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "export", sFileName); + string fullPath = Path.Combine(webRoot, "export", sFileName); Directory.CreateDirectory(Path.GetDirectoryName(fullPath));