public static HttpFile SaveFile(IObjectFile dObject, HttpPostedFileBase httpFile) { HttpFile retFile = new HttpFile(); string StoragePath = System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["FileStorage"]); string ValutPath = System.Configuration.ConfigurationManager.AppSettings["ValutPath"]; string SavePath = dObject.Type + "/" + dObject.OID.ToString(); try { retFile.FileSize = httpFile.ContentLength; /*폴더생성*/ DirectoryInfo di = new DirectoryInfo(StoragePath + "/" + ValutPath + "/" + SavePath); if (!di.Exists) { di.Create(); } FileInfo uploadFile = new FileInfo(di.FullName + "/" + httpFile.FileName); string ext = uploadFile.Extension; string purefileName = uploadFile.Name.Substring(0, uploadFile.Name.Length - ext.Length); string ConvFileName = SemsEncrypt.AESEncrypt256Text(uploadFile.Name, CommonConstant.TEXT_ENCRYPT_KEY); FileInfo fi = new FileInfo(di.FullName + "/" + ConvFileName); if (fi.Exists) { /*중복되지 않은 파일명 생성*/ int cnt = 1; string newFileName = ""; string pureName = purefileName; while (fi.Exists) { newFileName = pureName + " (" + (cnt++) + ")" + ext; ConvFileName = SemsEncrypt.AESEncrypt256Text(newFileName, CommonConstant.TEXT_ENCRYPT_KEY); fi = new FileInfo(StoragePath + "/" + ValutPath + "/" + SavePath + "/" + ConvFileName); } } SemsEncrypt.AESEncrypt256File(httpFile, fi.FullName, CommonConstant.FILE_ENCRYPT_KEY); retFile.OID = dObject.OID; retFile.Type = dObject.Type; retFile.OrgNm = uploadFile.Name; retFile.ConvNm = ConvFileName; retFile.Ext = ext; return(retFile); } catch (Exception ex) { throw ex; } }
public static bool InsertData(IObjectFile @object) { try { if (@object == null) { return(true); } @object.Files.ForEach(item => { HttpFile file = null; try { file = SemsValut.SaveFile(@object, item); file.CreateUs = 1; //HttpContext.Current.Session["UserOID"].ToString(); DaoFactory.SetInsert("Comm.InsFile", file); } catch (Exception ex) { if (item != null) { SemsValut.FileDelete(file); } throw ex; } }); return(false); } catch (Exception ex) { throw ex; } }