private static void CreateThumbnails(string path, string fileName, AspxCommonInfo aspxCommonObj) { try { StoreSettingConfig ssc = new StoreSettingConfig(); int largeSize = int.Parse(ssc.GetStoreSettingsByKey(StoreSetting.ItemLargeThumbnailImageSize, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)); int midSize = int.Parse(ssc.GetStoreSettingsByKey(StoreSetting.ItemMediumThumbnailImageSize, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)); int smallSize = int.Parse(ssc.GetStoreSettingsByKey(StoreSetting.ItemSmallThumbnailImageSize, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)); string largePath = path + "Large/" + fileName; string midPath = path + "Medium/" + fileName; string smallPath = path + "Small/" + fileName; string source = path + fileName; PictureManager.CreateThmnail(HttpContext.Current.Server.MapPath(source), largeSize, HttpContext.Current.Server.MapPath(largePath)); PictureManager.CreateThmnail(HttpContext.Current.Server.MapPath(source), midSize, HttpContext.Current.Server.MapPath(midPath)); PictureManager.CreateThmnail(HttpContext.Current.Server.MapPath(source), smallSize, HttpContext.Current.Server.MapPath(smallPath)); } catch (Exception) { throw; } }
private string SaveImage() { string FileName = string.Empty; try { FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + fileUploadFeatImage.FileName.Replace(" ", "").Replace("-", "").Replace("_", ""); string SavePath = Server.MapPath("/Modules/SageFeature/img/"); if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } SavePath = SavePath + FileName; fileUploadFeatImage.SaveAs(SavePath); string thumLarge = Server.MapPath("/Modules/SageFeature/img/ThumbLarge/"); if (!Directory.Exists(thumLarge)) { Directory.CreateDirectory(thumLarge); } thumLarge = thumLarge + FileName; PictureManager.CreateThmnail(SavePath, 500, thumLarge); File.SetAttributes(SavePath, FileAttributes.Normal); if (File.Exists(SavePath)) { File.Delete(SavePath); } return(FileName); } catch { return(FileName); } }
public void ResizeImage()//int itemID, string imgRootPath, string sourceFileCol, string pathCollection, string isActive, string imageType, string itemImageIds, string description, string displayOrder, string imgPreFix, int itemLargeThumbNailSize, int itemMediumThumbNailSize, int itemSmallThumbNailSize, string cultureName, int portalID { //string pathList = string.Empty; // string[] sourceFileList = sourceFileCol.Split('%'); // string destpath = HostingEnvironment.MapPath("~/" + imgRootPath); //if (!Directory.Exists(destpath)) // { //Directory.CreateDirectory(destpath); //} // Random randVar = new Random(); int itemLargeThumbNailSize = 600; int itemMediumThumbNailSize = 300; int itemSmallThumbNailSize = 125; try { //ArrayList Images = new ArrayList(); FileInfo[] Images; DirectoryInfo Folder = new DirectoryInfo(HostingEnvironment.MapPath("~/" + "Modules/AspxCommerce/AspxItemsManagement/uploads/")); Images = Folder.GetFiles(); string destpath = HostingEnvironment.MapPath("~/" + "Modules/AspxCommerce/AspxItemsManagement/uploads/"); string destination = ""; for (int i = 0; i < Images.Length; i++) { destination = destpath + Images[i].Name; //image Thumbnails generates here string vertualUrl0 = destpath + "Large\\"; string vertualUrl1 = destpath + "Medium\\"; string vertualUrl2 = destpath + "Small\\"; if (!Directory.Exists(vertualUrl0)) { Directory.CreateDirectory(vertualUrl0); } if (!Directory.Exists(vertualUrl1)) { Directory.CreateDirectory(vertualUrl1); } if (!Directory.Exists(vertualUrl2)) { Directory.CreateDirectory(vertualUrl2); } vertualUrl0 = vertualUrl0 + Images[i].Name; vertualUrl1 = vertualUrl1 + Images[i].Name; vertualUrl2 = vertualUrl2 + Images[i].Name; PictureManager.CreateThmnail(destination, itemLargeThumbNailSize, vertualUrl0); PictureManager.CreateThmnail(destination, itemMediumThumbNailSize, vertualUrl1); PictureManager.CreateThmnail(destination, itemSmallThumbNailSize, vertualUrl2); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Save Image and retrurn current Image Name /// </summary> /// <returns></returns> private string SaveImage() { if (fileCtlContentImage.HasFile) { Random rnd = new Random(); string FileName = rnd.Next(1, 100).ToString() + "_Banner.jpg"; string OrginalPath = Server.MapPath("~/Modules/SageBanner/images/Temp/"); string ThumbNailSmall = Server.MapPath("~/Modules/SageBanner/images/Thumbnail/small/"); string ThumbNailMedium = Server.MapPath("~/Modules/SageBanner/images/Thumbnail/medium/"); string ThumbNailLarge = Server.MapPath("~/Modules/SageBanner/images/Thumbnail/large/"); if (Directory.Exists(OrginalPath))// delete Temp Directory { string[] Icons = Directory.GetFiles(OrginalPath); foreach (string Images in Icons) { File.SetAttributes(Images, System.IO.FileAttributes.Normal); File.Delete(Images); } Directory.Delete(OrginalPath); } if (!Directory.Exists(OrginalPath))// create Empty Directory { Directory.CreateDirectory(OrginalPath); } if (!Directory.Exists(ThumbNailSmall)) { Directory.CreateDirectory(ThumbNailSmall); } if (!Directory.Exists(ThumbNailMedium)) { Directory.CreateDirectory(ThumbNailMedium); } if (!Directory.Exists(ThumbNailLarge)) { Directory.CreateDirectory(ThumbNailLarge); } OrginalPath = OrginalPath + FileName; fileCtlContentImage.SaveAs(OrginalPath); ThumbNailSmall = ThumbNailSmall + FileName; ThumbNailMedium = ThumbNailMedium + FileName; ThumbNailLarge = ThumbNailLarge + FileName; PictureManager.CreateThmnail(OrginalPath, 320, ThumbNailSmall); PictureManager.CreateThmnail(OrginalPath, 768, ThumbNailMedium); PictureManager.CreateThmnail(OrginalPath, 1450, ThumbNailLarge); fileCtlContentImage.Dispose(); return(FileName); } else { return(string.Empty); } }
public void SaveThumbnailImages(string ImageFilePath, int TargetSize, string TargetLocation, string fileName) { try { if (!Directory.Exists(TargetLocation)) { Directory.CreateDirectory(TargetLocation); } string SavePath = string.Empty; SavePath = Path.Combine(TargetLocation, fileName); PictureManager.CreateThmnail(ImageFilePath, TargetSize, SavePath); } catch (Exception ex) { throw ex; } }
public void SaveThumbnailImages(string ImageFilePath, int TargetSize, string TargetLocation, string fileName, bool isZoomThumbnail) { try { if (!Directory.Exists(TargetLocation)) { Directory.CreateDirectory(TargetLocation); } string saveLocation = TargetLocation + fileName; PictureManager.CreateThmnail(ImageFilePath, TargetSize, saveLocation, isZoomThumbnail); } catch (Exception ex) { throw ex; } }
/// <summary> /// Save Image and retrurn current Image Name /// </summary> /// <returns></returns> private string SaveImage() { if (fileBannerImage.HasFile) { string FileName = fileBannerImage.FileName; if (FileName.Length > 20) { FileName = Path.GetExtension(FileName); } FileName = System.DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + FileName; string OrginalPath = Server.MapPath("~/Modules/SageImageFlow/images/Temp/"); string ThumbNailSmall = Server.MapPath("~/Modules/SageImageFlow/images/Thumbnail/small/"); string ThumbNailLarge = Server.MapPath("~/Modules/SageImageFlow/images/Thumbnail/large/"); if (!Directory.Exists(OrginalPath))// create Empty Directory { Directory.CreateDirectory(OrginalPath); } if (!Directory.Exists(ThumbNailSmall)) { Directory.CreateDirectory(ThumbNailSmall); } if (!Directory.Exists(ThumbNailLarge)) { Directory.CreateDirectory(ThumbNailLarge); } OrginalPath = OrginalPath + FileName; fileBannerImage.SaveAs(OrginalPath); ThumbNailSmall = ThumbNailSmall + FileName; ThumbNailLarge = ThumbNailLarge + FileName; PictureManager.CreateThmnail(OrginalPath, 320, ThumbNailSmall); PictureManager.CreateThmnail(OrginalPath, 768, ThumbNailLarge); fileBannerImage.Dispose(); if (File.Exists(OrginalPath)) { File.Delete(OrginalPath); } return(FileName); } else { return(string.Empty); } }
protected void fileUpload_Click(object sender, EventArgs e) { if (this.fileUpload.HasFile) { string tempFilePath = Server.MapPath("~/Temp/sageframe.png"); string saveFinalPath = Server.MapPath("~/images/sageframe.png"); this.fileUpload.SaveAs(tempFilePath); PictureManager.CreateThmnail(tempFilePath, 332, 66, saveFinalPath); } string isChecked = string.Empty; isChecked = hdnIsShown.Value; SageFrame.Utilities.Config.UpdateSageFrameVersionLoad(isChecked); if (isChecked == "true") { showVersion(); } else { hideVersion(); } }
public string MoveFileToSpecificFolder(string tempFolder, string prevFilePath, string newFilePath, string destinationFolder, int ID, string imgPreFix) { //imagePath = imagePath.Replace("../../", ""); newFilePath = newFilePath.Replace("/", "\\"); string strRootPath = HostingEnvironment.MapPath("~/"); string fileExt = newFilePath.Substring(newFilePath.LastIndexOf(".")); Random rnd = new Random(); string fileName = imgPreFix + ID + '_' + rnd.Next(111111, 999999).ToString() + fileExt; string sourceFile = strRootPath + newFilePath; string destinationFile = string.Empty; destinationFolder = strRootPath + destinationFolder; try { if (File.Exists(sourceFile)) { // To move a file or folder to a new location: if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } destinationFile = destinationFolder + fileName; if (sourceFile != destinationFile) { if (File.Exists(destinationFile)) { File.Delete(destinationFile); } System.IO.File.Move(sourceFile, destinationFile); if (prevFilePath != "") { prevFilePath = prevFilePath.Replace("/", "\\"); prevFilePath = strRootPath + prevFilePath; // System.IO.File.Delete(prevFilePath); } string vertualUrl0 = destinationFolder + "Large\\"; string vertualUrl1 = destinationFolder + "Medium\\"; string vertualUrl2 = destinationFolder + "Small\\"; if (!Directory.Exists(vertualUrl0)) { Directory.CreateDirectory(vertualUrl0); } if (!Directory.Exists(vertualUrl1)) { Directory.CreateDirectory(vertualUrl1); } if (!Directory.Exists(vertualUrl2)) { Directory.CreateDirectory(vertualUrl2); } vertualUrl0 = vertualUrl0 + fileName; vertualUrl1 = vertualUrl1 + fileName; vertualUrl2 = vertualUrl2 + fileName; string[] imageType = new string[] { "jpg", "jpeg", "jpe", "gif", "bmp", "png", "ico" }; bool isValidImage = false; foreach (string x in imageType) { if (fileExt.Contains(x)) { isValidImage = true; break; } } if (isValidImage) { PictureManager.CreateThmnail(destinationFile, 320, vertualUrl0); PictureManager.CreateThmnail(destinationFile, 240, vertualUrl1); PictureManager.CreateThmnail(destinationFile, 125, vertualUrl2); } else { System.IO.File.Copy(destinationFile, vertualUrl0); System.IO.File.Copy(destinationFile, vertualUrl1); System.IO.File.Copy(destinationFile, vertualUrl2); } ////Check previously unsaved files and delete //string tempFolderPath = strRootPath + tempFolder; //DirectoryInfo temDir = new DirectoryInfo(tempFolderPath); //if (temDir.Exists) //{ // FileInfo[] files = temDir.GetFiles(); // foreach (FileInfo file in files) // { // if (file.CreationTime.ToShortDateString() != DateTime.Now.ToShortDateString()) // { // System.IO.File.Delete(file.FullName); // } // } //} } destinationFile = destinationFile.Replace(strRootPath, ""); destinationFile = destinationFile.Replace("\\", "/"); } } catch (Exception e) { throw e; } return(destinationFile); }
public void FileMover(int itemID, string imgRootPath, string sourceFileCol, string pathCollection, string isActive, string imageType, string description, string displayOrder, string imgPreFix, int itemLargeThumbNailSize, int itemMediumThumbNailSize, int itemSmallThumbNailSize) { string pathList = string.Empty; string[] sourceFileList = sourceFileCol.Split('%'); string destpath = HostingEnvironment.MapPath("~/" + imgRootPath); if (!Directory.Exists(destpath)) { Directory.CreateDirectory(destpath); } Random randVar = new Random(); try { string[] sourceList = pathCollection.Split('%'); // DirectoryInfo destDir = new DirectoryInfo(destpath); #region FileDelete // Delete images from dstination folder of same itemID /* * if (destDir.Exists) * { * FileInfo[] files = GetFilesList(int.Parse(itemID), destDir); * * string listFiles = string.Empty; * int j = 0; * if (files.Length != 0) * { * while (j < files.Length) * { * * if (files[j].FullName.Contains(".db") || files[j].FullName.Contains(".DB")) * { * System.IO.File.Delete(files[j].FullName); * } * j++; * } * foreach (FileInfo file in files) * { * foreach (string fileStr in sourceList) * { * string sourceCol = HostingEnvironment.MapPath("~/" + fileStr); * string destCol = file.DirectoryName + "\\" + file; * if (destCol == sourceCol) * { * break; * } * else * { * listFiles += sourceCol + ","; * } * * } * } * } * * * * * * if (listFiles.Contains(",")) * { * listFiles = listFiles.Remove(listFiles.LastIndexOf(",")); * * * string[] delFileCol = listFiles.Split(','); * * int count = delFileCol.Length; * int i = 0; * while (i < count) * { * if (File.Exists(delFileCol[i])) * { * if (delFileCol[i].Contains(".db") || delFileCol[i].Contains(".DB")) * { * System.IO.File.Delete(delFileCol[i]); * } * * else * { * string[] path_Splitter = delFileCol[i].ToString().Split('\\'); * int words_length = path_Splitter.Length; * string[] words_Splitter = path_Splitter[words_length - 1].Split('_'); * int length = words_Splitter.Length; * if (words_Splitter[length - 2].ToString() == itemID) * { * System.IO.File.Delete(delFileCol[i]); * } * } * } * i++; * } * } * }*/ #endregion //Move files from source to destination folder for (int i = 0; i < sourceFileList.Length; i++) { string sourceCol = HostingEnvironment.MapPath("~/" + sourceList[i]); string fileExt = sourceFileList[i].Substring(sourceFileList[i].LastIndexOf(".")); string fileName = imgPreFix + itemID + '_' + randVar.Next(111111, 999999).ToString() + fileExt; pathList += imgRootPath + fileName + "%"; //TODO:: make only image Name instead Path sourceFileList[i] = fileName; if (destpath != null) { string destination = Path.Combine(destpath, sourceFileList[i]); if (sourceCol != destination) { if (File.Exists(sourceCol) && !File.Exists(destination)) { if (sourceCol != null) { File.Copy(sourceCol, destination); } //image Thumbnails generates here string vertualUrl0 = destpath + "Large\\"; string vertualUrl1 = destpath + "Medium\\"; string vertualUrl2 = destpath + "Small\\"; if (!Directory.Exists(vertualUrl0)) { Directory.CreateDirectory(vertualUrl0); } if (!Directory.Exists(vertualUrl1)) { Directory.CreateDirectory(vertualUrl1); } if (!Directory.Exists(vertualUrl2)) { Directory.CreateDirectory(vertualUrl2); } vertualUrl0 = vertualUrl0 + fileName; vertualUrl1 = vertualUrl1 + fileName; vertualUrl2 = vertualUrl2 + fileName; string[] imageTypeFiles = new string[] { "jpg", "jpeg", "jpe", "gif", "bmp", "png", "ico" }; bool isValidImage = false; foreach (string x in imageTypeFiles) { if (fileExt.Contains(x)) { isValidImage = true; break; } } if (isValidImage) { PictureManager.CreateThmnail(destination, itemLargeThumbNailSize, vertualUrl0); PictureManager.CreateThmnail(destination, itemMediumThumbNailSize, vertualUrl1); PictureManager.CreateThmnail(destination, itemSmallThumbNailSize, vertualUrl2); } else { System.IO.File.Copy(destination, vertualUrl0); System.IO.File.Copy(destination, vertualUrl1); System.IO.File.Copy(destination, vertualUrl2); } } } } } if (pathList.Contains("%")) { pathList = pathList.Remove(pathList.LastIndexOf("%")); } //Save to database ImageUploaderSqlhandler imageSql = new ImageUploaderSqlhandler(); imageSql.SaveImageSettings(itemID, pathList, isActive, imageType, description, displayOrder); //// delete files created earlier //DirectoryInfo temDir = new DirectoryInfo(sourcepath); //if (temDir.Exists) //{ // FileInfo[] files = temDir.GetFiles(); // foreach (FileInfo file in files) // { // if (file.CreationTime.ToShortDateString() != DateTime.Now.ToShortDateString()) // { // System.IO.File.Delete(file.FullName); // } // } //} } catch (Exception ex) { throw ex; } }
public string MoveVariantsImageFile(string tempFolder, string destPath, CostVariantsCombination itemCostVariants, AspxCommonInfo aspxCommonObj) { int storeID, portalID; string culture; storeID = aspxCommonObj.StoreID; portalID = aspxCommonObj.PortalID; culture = aspxCommonObj.CultureName; StoreSettingConfig ssc = new StoreSettingConfig(); int itemLargeThumbNailSize = Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemLargeThumbnailImageSize, storeID, portalID, culture)); int itemMediumThumbNailSize = Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemMediumThumbnailImageSize, storeID, portalID, culture)); int itemSmallThumbNailSize = Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemSmallThumbnailImageSize, storeID, portalID, culture)); destPath = destPath.Replace("/", "\\"); string destinationFolder = HostingEnvironment.MapPath("~/") + destPath; string imageFilePathList = string.Empty; foreach (var obj in itemCostVariants.VariantOptions) { if (!string.IsNullOrEmpty(obj.ImageFile)) { imageFilePathList = obj.ImageFile; string[] sourceFileList = imageFilePathList.Split('@'); // To move a file or folder to a new location: if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } for (int i = 0; i < sourceFileList.Length; i++) { string fileExt = sourceFileList[i].Substring(sourceFileList[i].LastIndexOf(".")); string fileName = sourceFileList[i]; fileName = fileName.Remove(0, 1); string sourceCol = HostingEnvironment.MapPath("~/" + sourceFileList[i]); if (destinationFolder != null) { string destination = Path.Combine(destinationFolder, fileName); if (sourceCol != destination) { if (File.Exists(sourceCol) && !File.Exists(destination)) { if (sourceCol != null) { File.Copy(sourceCol, destination); } //image Thumbnails generates here string vertualUrl0 = destinationFolder + "Large\\"; string vertualUrl1 = destinationFolder + "Medium\\"; string vertualUrl2 = destinationFolder + "Small\\"; if (!Directory.Exists(vertualUrl0)) { Directory.CreateDirectory(vertualUrl0); } if (!Directory.Exists(vertualUrl1)) { Directory.CreateDirectory(vertualUrl1); } if (!Directory.Exists(vertualUrl2)) { Directory.CreateDirectory(vertualUrl2); } vertualUrl0 = vertualUrl0 + fileName; vertualUrl1 = vertualUrl1 + fileName; vertualUrl2 = vertualUrl2 + fileName; string[] imageTypeFiles = new string[] { "jpg", "jpeg", "jpe", "gif", "bmp", "png", "ico" }; bool isValidImage = false; foreach (string x in imageTypeFiles) { if (fileExt.Contains(x)) { isValidImage = true; break; } } if (isValidImage) { PictureManager.CreateThmnail(destination, itemLargeThumbNailSize, vertualUrl0); PictureManager.CreateThmnail(destination, itemMediumThumbNailSize, vertualUrl1); PictureManager.CreateThmnail(destination, itemSmallThumbNailSize, vertualUrl2); } else { System.IO.File.Copy(destination, vertualUrl0); System.IO.File.Copy(destination, vertualUrl1); System.IO.File.Copy(destination, vertualUrl2); } } } } } } } return("sucess"); }