Selaa lähdekoodia

出入境费用明细 下载文件名称验证

LEIYI 4 viikkoa sitten
vanhempi
commit
0afe01634c

+ 8 - 6
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1046,8 +1046,6 @@ namespace OASystem.API.Controllers
             }
         }
 
-
-
         /// <summary>
         /// 接团流程操作(增改)
         /// 安卓端使用 建团时添加客户名单
@@ -8032,7 +8030,8 @@ FROM
                         #endregion
 
                         //文件名
-                        string strFileName = $"{_EnterExitCosts.DraftName}出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
+                        string strFileName = $"{_EnterExitCosts.DraftName}_出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
+                        strFileName = CommonFun.ValidFileName(strFileName);
                         AsposeHelper.removewatermark_v2180();
                         doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
                         string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
@@ -8253,7 +8252,9 @@ FROM
                         }
 
                         //模板文件名
-                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
+                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}_因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
+
+                        strFileName = CommonFun.ValidFileName(strFileName);
                         doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
                         string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
 
@@ -8490,7 +8491,7 @@ FROM
                         wb.CalculateFormula(true);
 
                         //模板文件名
-                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
+                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}_四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
                         designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
                         string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
                         if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
@@ -8579,7 +8580,8 @@ FROM
                         }
 
                         //模板文件名
-                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
+                        string strFileName = $"草稿_{_EnterExitCosts.DraftName}_成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
+                        strFileName = CommonFun.ValidFileName(strFileName);
                         doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
                         string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
 

+ 15 - 0
OASystem/OASystem.Infrastructure/Tools/CommonFun.cs

@@ -131,6 +131,21 @@ public static class CommonFun
         if (!Directory.Exists(dir))
             Directory.CreateDirectory(dir);
     }
+
+    /// <summary>
+    /// 验证文件名称
+    /// </summary>
+    /// <param name="fileName"></param>
+    /// <returns></returns>
+    public static string ValidFileName(string fileName)
+    {
+        if (string.IsNullOrEmpty(fileName)) return Guid.NewGuid().ToString();
+
+        // 获取非法文件名字符
+        char[] invalidChars = Path.GetInvalidFileNameChars();
+
+        return new string(fileName.Where(c => !invalidChars.Contains(c)).ToArray());
+    }
     #endregion
 
     #region IP