fix upload and download
This commit is contained in:
@ -102,8 +102,12 @@ public abstract class BaseController : ControllerBase
|
|||||||
protected (string, string) DownloadImportTemplate<T>(List<T> list, string fileName)
|
protected (string, string) DownloadImportTemplate<T>(List<T> list, string fileName)
|
||||||
{
|
{
|
||||||
IWebHostEnvironment webHostEnvironment = ServiceContext.GetService<IWebHostEnvironment>();
|
IWebHostEnvironment webHostEnvironment = ServiceContext.GetService<IWebHostEnvironment>();
|
||||||
|
var webRoot = webHostEnvironment.WebRootPath
|
||||||
|
?? Path.Combine(webHostEnvironment.ContentRootPath, "wwwroot");
|
||||||
|
if (!Directory.Exists(webRoot)) Directory.CreateDirectory(webRoot);
|
||||||
|
|
||||||
string sFileName = $"{fileName}.xlsx";
|
string sFileName = $"{fileName}.xlsx";
|
||||||
string fullPath = Path.Combine(webHostEnvironment.WebRootPath, "ImportTemplate", sFileName);
|
string fullPath = Path.Combine(webRoot, "ImportTemplate", sFileName);
|
||||||
|
|
||||||
//不存在模板创建模板
|
//不存在模板创建模板
|
||||||
if (!Directory.Exists(fullPath))
|
if (!Directory.Exists(fullPath))
|
||||||
@ -124,8 +128,12 @@ public abstract class BaseController : ControllerBase
|
|||||||
protected (string, string) ExportExcelMini<T>(List<T> list, string sheetName, string fileName)
|
protected (string, string) ExportExcelMini<T>(List<T> list, string sheetName, string fileName)
|
||||||
{
|
{
|
||||||
IWebHostEnvironment webHostEnvironment = ServiceContext.GetService<IWebHostEnvironment>();
|
IWebHostEnvironment webHostEnvironment = ServiceContext.GetService<IWebHostEnvironment>();
|
||||||
|
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 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));
|
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user