private void UploadFile(Guid stiforsub_coopId) { HttpFileCollection hfc = Request.Files; string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; string dir = appPath + CY.Utility.Common.AnnexUtility.StimulatAppSetFileDir; string fileName = string.Empty; string fileExtention = string.Empty; string realFileName = string.Empty; DirectoryInfo di = new DirectoryInfo(dir); if (!di.Exists) { di.Create(); } CY.CSTS.Core.Business.AnnexType docType = null; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile file = hfc[i]; realFileName = CY.Utility.Common.FileUtility.GetFileName(file.FileName); fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(file.FileName); fileName = Guid.NewGuid().ToString(); if (fileExtention == ".jpg" || fileExtention == ".jpeg" || fileExtention == ".gif" || fileExtention == ".png" || fileExtention == ".bmp") { docType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (docType == null) { docType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; docType.Save(); } } else if (fileExtention == ".csv" || fileExtention == ".doc" || fileExtention == ".docx" || fileExtention == ".pdf" || fileExtention == ".ppt" || fileExtention == ".txt" || fileExtention == ".rar" || fileExtention == ".zip") { docType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.DocAnnexType); if (docType == null) { docType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; docType.Save(); } } else { continue; } file.SaveAs(dir + fileName + fileExtention); CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex(); annex.Name = realFileName + fileExtention; annex.ContentID = stiforsub_coopId; annex.AnnexTypeID = docType.Id; annex.AnnexURI = CY.Utility.Common.AnnexUtility.StimulatAppSetFileDir + fileName + fileExtention; annex.Save(); } }
private void SaveImgs(System.Guid contentId) { try { string[] imgNames = null; string[] imgPaths = null; if (string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgpath")) || string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgname"))) { return; } imgPaths = CY.Utility.Common.RequestUtility.GetFormString("imgpath").Split(','); imgNames = CY.Utility.Common.RequestUtility.GetFormString("imgName").Split(','); string appPath = string.Empty; string imgName = string.Empty; string imgExtention = string.Empty; string dirPath = string.Empty; if (imgPaths != null && imgNames != null && imgPaths.Length == imgNames.Length) { for (int i = 0; i < imgPaths.Length; i++) { CY.CSTS.Core.Business.AnnexType imgType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType); if (imgType == null) { imgType = new CY.CSTS.Core.Business.AnnexType(); imgType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType; imgType.Save(); } appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath; imgName = CY.Utility.Common.FileUtility.GetFileName(imgNames[i]); imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgNames[i]); dirPath = CY.Utility.Common.SiteUtility.CurServer.MapPath(imgPaths[i]); if (File.Exists(dirPath)) { CY.CSTS.Core.Business.Annex imgAnnex = new CY.CSTS.Core.Business.Annex(); imgAnnex.Name = imgName; imgAnnex.AnnexTypeID = imgType.Id; imgAnnex.ContentID = contentId; imgAnnex.AnnexURI = CY.Utility.Common.AnnexUtility.ManufacturerAnneImgDir + imgName + imgExtention; imgAnnex.Save(); } } } } catch (Exception ex) { throw ex; } finally { } }