From 8e17fef32fb04df9054698a8597cb5616a6f29b4 Mon Sep 17 00:00:00 2001 From: glz <694770232@qq.com> Date: Wed, 17 Jun 2026 17:42:40 +0800 Subject: [PATCH] fix upload and download --- .../Controllers/BaseController.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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));