public virtual ImagePreviewDTO SaveAspect(System.Web.HttpPostedFile file) { string thumbFolder = string.Format("{0}\\Thumb", this._folderServerPath); if (!System.IO.Directory.Exists(this._orignalImageServerPath)) { System.IO.Directory.CreateDirectory(this._orignalImageServerPath); } if (!System.IO.Directory.Exists(thumbFolder)) { System.IO.Directory.CreateDirectory(thumbFolder); } string fileName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + file.FileName; string orignalPath = string.Format(this._orignalImageServerPath + "\\{0}", fileName); string thumbPath = string.Format(thumbFolder + "\\{0}", fileName); ImagePreviewDTO previewDTO = new ImagePreviewDTO(); previewDTO.FileName = fileName; previewDTO.Key = Guid.NewGuid().ToString(); previewDTO.OrignalPath = string.Format("{0}/Orignal/{1}", this._folderPath, fileName); try { //保存原图 file.SaveAs(orignalPath); //缩略图100*65 if (fileName.IndexOf(".doc") > 0 || fileName.IndexOf(".docx") > 0) { string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons"); orignalPath = string.Format(iconServerPath + "\\{0}", "word.png"); thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW"); previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); } else if (fileName.IndexOf(".xls") > 0 || fileName.IndexOf("xlsx") > 0) { string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons"); orignalPath = string.Format(iconServerPath + "\\{0}", "excel.png"); thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW"); previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); } else if (fileName.IndexOf("ppt") > 0 || fileName.IndexOf(".pptx") > 0) { string iconServerPath = System.Web.HttpContext.Current.Server.MapPath("/ImageUpload/Icons"); orignalPath = string.Format(iconServerPath + "\\{0}", "ppt.png"); thumbPath = string.Format(thumbFolder + "\\{0}", fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW"); previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName.Substring(0, fileName.LastIndexOf(".")) + ".png"); } else { IWEHAVE.ERP.GAIA.WEBUtil.FileManage.MakeThumbnail(orignalPath, thumbPath, 100, 65, "AHW"); previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, fileName); } } catch (System.IO.IOException ex) { if (System.IO.File.Exists(orignalPath)) { System.IO.File.Delete(orignalPath); } if (System.IO.File.Exists(thumbPath)) { System.IO.File.Delete(thumbPath); } } return previewDTO; }
public CompanyImagePreviewDTO(ImagePreviewDTO previewDTO) { this.Key = previewDTO.Key; this.FileName = previewDTO.FileName; this.OrignalPath = previewDTO.OrignalPath; this.ThumbPath = previewDTO.ThumbPath; }
public virtual List<ImagePreviewDTO> LoadAspect() { string orignalFolder = string.Format("{0}\\Orignal", this._folderServerPath); string thumbFolder = string.Format("{0}\\Thumb", this._folderServerPath); List<ImagePreviewDTO> previewDTOList = new List<ImagePreviewDTO>(); if (System.IO.Directory.Exists(orignalFolder)) { foreach (string fileName in System.IO.Directory.GetFiles(orignalFolder)) { ImagePreviewDTO previewDTO = new ImagePreviewDTO(); previewDTO.Key = Guid.NewGuid().ToString(); previewDTO.FileName = System.IO.Path.GetFileName(fileName); previewDTO.OrignalPath = string.Format("{0}/Orignal/{1}", this._folderPath, previewDTO.FileName); if (previewDTO.FileName.IndexOf(".doc") > 0 || previewDTO.FileName.IndexOf(".docx") > 0 || previewDTO.FileName.IndexOf(".xls") > 0 || previewDTO.FileName.IndexOf(".xlsx") > 0 || previewDTO.FileName.IndexOf(".ppt") > 0 || previewDTO.FileName.IndexOf(".pptx") > 0) { previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, previewDTO.FileName.Substring(0, previewDTO.FileName.IndexOf(".")) + ".png"); } else { previewDTO.ThumbPath = string.Format("{0}/Thumb/{1}", this._folderPath, previewDTO.FileName); } previewDTOList.Add(previewDTO); } } return previewDTOList; }