using System.IO; namespace BLL { /// /// 上传附件相关 /// public class UploadFileService { #region 附件上传 /// /// 附件上传 /// /// 上传控件 /// 上传路径 /// 定义路径 /// public static string UploadAttachment(string rootPath, FineUIPro.FileUpload fileUpload, string fileUrl, string constUrl) { if (!string.IsNullOrEmpty(fileUrl)) ////是否存在附件 存在则删除 { string urlFullPath = rootPath + fileUrl; if (File.Exists(urlFullPath)) { File.Delete(urlFullPath); } } string initFullPath = rootPath + constUrl; if (!Directory.Exists(initFullPath)) { Directory.CreateDirectory(initFullPath); } string filePath = fileUpload.PostedFile.FileName; string fileName = Funs.GetNewFileName() + "~" + Path.GetFileName(filePath); int count = fileUpload.PostedFile.ContentLength; string savePath = constUrl + fileName; string fullPath = initFullPath + fileName; if (!File.Exists(fullPath)) { byte[] buffer = new byte[count]; Stream stream = fileUpload.PostedFile.InputStream; stream.Read(buffer, 0, count); MemoryStream memoryStream = new MemoryStream(buffer); FileStream fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write); memoryStream.WriteTo(fs); memoryStream.Flush(); memoryStream.Close(); fs.Flush(); fs.Close(); memoryStream = null; fs = null; //if (!string.IsNullOrEmpty(fileUrl)) //{ // fileUrl += "," + savePath; //} //else //{ // fileUrl += savePath; //} fileUrl = savePath; } else { fileUrl = string.Empty; } return fileUrl; } #endregion #region 附件资源删除 /// /// 附件资源删除 /// /// /// public static void DeleteFile(string rootPath, string fileUrl) { if (!string.IsNullOrEmpty(fileUrl)) { string[] strs = fileUrl.Trim().Split(','); foreach (var item in strs) { string urlFullPath = rootPath + item; if (File.Exists(urlFullPath)) { File.Delete(urlFullPath); } } } } #endregion #region 上传文件路径 /// /// 安全组织体系 /// public const string HSSEOrganizeFilePath = "FileUpload\\HSSEOrganize\\"; /// /// 安全管理机构-附件路径 /// public const string HSSEManageFilePath = "FileUpload\\HSSEManage\\"; /// /// 标准规范-附件路径 /// public static string HSSEStandardsListFilePath = "FileUpload\\HSSEStandardsList\\"; /// ///法律法规-附件路径 /// public static string LawRegulationFilePath = "FileUpload\\LawRegulation\\"; /// /// 管理规定-附件路径 /// public static string ManageRuleFilePath = "FileUpload\\ManageRule\\"; /// /// 生产管理规章制度-附件路径 /// public static string RulesRegulationsFilePath = "FileUpload\\RulesRegulations\\"; /// /// 培训教材库-附件路径 /// public static string TrainingFilePath = "FileUpload\\Training\\"; /// /// 事故案例库-附件路径 /// public static string AccidentCaseFilePath = "FileUpload\\AccidentCase\\"; /// /// HAZOP-附件路径 /// public static string HAZOPFilePath = "FileUpload\\HAZOP\\"; /// /// 安全试题库-附件路径 /// public static string TrainTestDBFilePath = "FileUpload\\TrainTestDB\\"; /// /// 安全专家-附件路径 /// public static string ExpertFilePath = "FileUpload\\Expert\\"; /// /// 应急预案-附件路径 /// public const string EmergencyFilePath = "FileUpload\\Emergency\\"; /// /// 专项方案-附件路径 /// public const string SpecialSchemeFilePath = "FileUpload\\SpecialScheme\\"; /// /// 安全监督检查报告-附件路径 /// public static string SuperviseCheckReportFilePath = "FileUpload\\SuperviseCheckReport\\"; /// /// 安全生产快报-附件路径 /// public static string SafeProductionExpressFilePath = "FileUpload\\SafeProductionExpress\\"; /// /// 安全交流-附件路径 /// public static string ExchangeFilePath = "FileUpload\\Exchange\\"; /// /// 安全生产数据季报-附件路径 /// public static string SafetyQuarterlyReportFilePath = "FileUpload\\SafetyQuarterlyReport\\"; /// /// 在线督查 /// public const string OnLineSupervisionFilePath = "FileUpload\\OnLineSupervision\\"; /// /// 项目评价 /// public const string ProjectEvaluationFilePath = "FileUpload\\ProjectEvaluation\\"; /// /// 事故快报 /// public const string ProjectAccidentFilePath = "FileUpload\\ProjectAccident\\"; /// /// 版本附件路径 /// public const string SysVersionFilePath = "FileUpload\\SysVersion\\"; /// /// 测温点布置示意图附件路径 /// public const string CewendianshcFilePath = "FileUpload\\HotProcessCard1\\"; /// /// 理论焊后热处理曲线 /// public const string LilunhanhouFilePath = "FileUpload\\HotProcessCard2\\"; /// /// 二维码上传路径 /// public const string QRCodeImageFilePath = "FileUpload\\QRCodeFile\\"; #endregion } }