private void Process_AddLibraryItem() { PermissionData security_data; //Dim folder_data As FolderData LibraryConfigData lib_setting_data; Collection pagedata; string strOperation = ""; string strLibType = ""; string strContentId = ""; long CurrentUserID = 0; Ektron.Cms.Library.EkLibrary m_refLibrary; string FileName = ""; string NewFilename = ""; string MediaPath = ""; string Extensions = ""; string[] FilenameArray; bool ret = false; bool uploadok = false; string[] ExtensionArray; //, gtLibraries int iLoop; bool bThumbnail = true; object szPhysicalPath; // ,ThumbLBString string actErrorString; CurrentUserID = _ContentApi.UserId; m_refLibrary = _ContentApi.EkLibraryRef; Ektron.Cms.DataIO.EkLibraryRW dataLibObj; dataLibObj = new Ektron.Cms.DataIO.EkContentRW(_ContentApi.RequestInformationRef); Collection cItemInfo = new Collection(); try { if ((_Type == "images") || (_Type == "files")) { int fileLength = frm_filename.PostedFile.ContentLength; byte[] fileData = new byte[fileLength]; frm_filename.PostedFile.InputStream.Read(fileData, 0, fileLength); Stream stream = new MemoryStream(fileData); if (EkFunctions.IsImage(Path.GetExtension(frm_filename.PostedFile.FileName))) { if (!EkFunctions.isImageStreamValid(stream)) { throw new Exception("The image is corrupted or not in correct format."); } } _FolderId = Convert.ToInt64(Request.Form["frm_folder_id"]); strLibType = Request.Form["frm_libtype"]; strOperation = Request.Form["frm_operation"]; FileName = (string)(frm_filename.PostedFile.FileName.Substring((frm_filename.PostedFile.FileName).LastIndexOf("\\") + 1)); FileName = FileName.Replace("%", ""); lib_setting_data = _ContentApi.GetLibrarySettings(_FolderId); security_data = _ContentApi.LoadPermissions(_FolderId, "folder", 0); strContentId = Request.Form["frm_content_id"]; pagedata = new Collection(); pagedata.Add(_FolderId, "ParentID", null, null); pagedata.Add(Request.Form["frm_library_id"], "LibraryID", null, null); pagedata.Add(strLibType, "LibraryType", null, null); pagedata.Add(Request.Form["frm_title"], "LibraryTitle", null, null); pagedata.Add(strContentId, "ContentID", null, null); NewFilename = Strings.Trim(Request.Form["frm_oldfilename"]); if (((strOperation.ToLower() != "overwrite") && (((security_data.CanAddToImageLib) && (strLibType == "images")) || ((security_data.CanAddToFileLib) && (strLibType == "files")) || ((security_data.CanAddToHyperlinkLib) && (strLibType == "hyperlinks")) || ((security_data.CanAddToQuicklinkLib) && (strLibType == "quicklinks")))) || ((security_data.CanOverwriteLib) && (strOperation.ToLower() == "overwrite"))) { pagedata.Add(CurrentUserID, "UserID", null, null); FilenameArray = FileName.Split('.'); if (strLibType == "images") { Extensions = lib_setting_data.ImageExtensions; MediaPath = lib_setting_data.ImageDirectory; } else { Extensions = lib_setting_data.FileExtensions; MediaPath = lib_setting_data.FileDirectory; } if ((FilenameArray.Length - 1) >= 1) { ExtensionArray = Extensions.Split(','); for (iLoop = 0; iLoop <= (ExtensionArray.Length - 1); iLoop++) { if (Strings.LCase(FilenameArray[FilenameArray.Length - 1]).Trim() == Strings.LCase((string)(ExtensionArray[iLoop])).Trim()) { uploadok = true; break; } } if (uploadok == true) { if (strOperation.ToLower() == "overwrite") { pagedata.Add("OverwriteLib", "UpdateLibData", null, null); strOperation = "overwrite"; } else { strOperation = "makeunique"; } szPhysicalPath = Server.MapPath(MediaPath); if (!Directory.Exists(szPhysicalPath.ToString())) { Directory.CreateDirectory(szPhysicalPath.ToString()); } if (strOperation == "overwrite") { actErrorString = NewFilename; } else { actErrorString = FileName; } string strTmpFilename; string strTmpFileExtn; int iUnqueNameIdentifier =0 ; FileInfo CheckFile; actErrorString = Strings.Replace(actErrorString.ToString(), "/", "\\", 1, -1, 0); string[] st = Strings.Split(actErrorString.ToString(), "\\", -1, 0); strTmpFilename = st[st.Length-1]; if ((Strings.Right(szPhysicalPath.ToString(), 1) != "\\")) { szPhysicalPath = szPhysicalPath + "\\"; } actErrorString = strTmpFilename; strTmpFileExtn = actErrorString.Substring(actErrorString.LastIndexOf(".")); strTmpFilename = Strings.Replace(actErrorString.ToString(), strTmpFileExtn.ToString(), "", 1, -1, 0); if (strOperation == "makeunique") { CheckFile = new FileInfo(szPhysicalPath + actErrorString); if (CheckFile.Exists) { while (CheckFile.Exists) { iUnqueNameIdentifier = iUnqueNameIdentifier + 1; actErrorString = strTmpFilename + "(" + iUnqueNameIdentifier + ")" + strTmpFileExtn; CheckFile = new FileInfo(szPhysicalPath + actErrorString); } } } if (!Directory.Exists(szPhysicalPath.ToString())) { Directory.CreateDirectory(szPhysicalPath.ToString()); } try { if ((strOperation.ToLower() != "overwrite") && (strLibType == "images" || strLibType == "files")) { cItemInfo = dataLibObj.GetChildLibraryItemByTitlev2_0(Convert.ToString( Request.Form["frm_title"]), _FolderId, strLibType,Convert.ToInt32( EkEnumeration.CMSContentType.LibraryItem)); if ((cItemInfo.Count > 0) && (Convert.ToInt32( cItemInfo["ContentLanguage"]) == _ContentApi.RequestInformationRef.ContentLanguage)) { Utilities.ShowError(_MessageHelper.GetMessage("com: library entry already exists")); return; } } } catch (Exception) { } frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString); if (strLibType == "images") { try { Utilities.ProcessThumbnail(Server.MapPath(MediaPath), actErrorString.ToString()); } catch (Exception) { bThumbnail = false; } } else { bThumbnail = false; } //----------------- Load Balance ------------------------------------------------------ LoadBalanceData[] loadbalance_data; int i = 0; loadbalance_data = _ContentApi.GetAllLoadBalancePathsExtn(_FolderId, strLibType); if (!(loadbalance_data == null)) { for (i = 0; i <= loadbalance_data.Length - 1; i++) { szPhysicalPath = Server.MapPath(loadbalance_data[i].Path); if ((Strings.Right(szPhysicalPath.ToString(), 1) != "\\")) { szPhysicalPath = szPhysicalPath + "\\"; } frm_filename.PostedFile.SaveAs(szPhysicalPath + actErrorString); if (bThumbnail) { Utilities.ProcessThumbnail(szPhysicalPath.ToString(), actErrorString.ToString()); } } } pagedata.Add(MediaPath + actErrorString, "LibraryFilename", null, null); } else { throw (new Exception(_MessageHelper.GetMessage("error: invalid extension"))); } } else { throw (new Exception(_MessageHelper.GetMessage("error: invalid extension"))); } } else { throw (new Exception(_MessageHelper.GetMessage("com: user does not have permission"))); } } else { pagedata = new Collection(); pagedata.Add(Request.Form["frm_folder_id"], "ParentID", null, null); pagedata.Add(Request.Form["frm_libtype"], "LibraryType", null, null); pagedata.Add(Request.Form["frm_title"], "LibraryTitle", null, null); pagedata.Add(Request.Form["frm_filename"], "LibraryFilename", null, null); pagedata.Add(Request.Form["frm_content_id"], "ContentID", null, null); pagedata.Add(_ContentLanguage, "ContentLanguage", null, null); pagedata.Add(CurrentUserID, "UserID", null, null); } if (_Type != "quicklinks" && _Type != "forms") { pagedata.Add(GetFormTeaserData(), "ContentTeaser", null, null); pagedata.Add(CollectMetaField(), "ContentMetadata", null, null); } //Adding the Taxonomy category info if ((Request.Form["TaxonomyOverrideId"] != null) && Convert.ToInt64(Request.Form["TaxonomyOverrideId"]) != 0) { TaxonomyOverrideId = Convert.ToInt64( Request.Form["TaxonomyOverrideId"]); TaxonomyTreeIdList = Convert.ToString( TaxonomyOverrideId); } if ((Request.Form[taxonomyselectedtree.UniqueID] != null) && Request.Form[taxonomyselectedtree.UniqueID] != "") { TaxonomyTreeIdList = Request.Form[taxonomyselectedtree.UniqueID]; if (TaxonomyTreeIdList.Trim().EndsWith(",")) { TaxonomyTreeIdList = TaxonomyTreeIdList.Substring(0, TaxonomyTreeIdList.Length - 1); } } if (TaxonomyTreeIdList.Trim() == string.Empty && TaxonomySelectId > 0) { TaxonomyTreeIdList = Convert.ToString( TaxonomySelectId); } pagedata.Add(TaxonomyTreeIdList, "Taxonomy", null, null); ///' if (strOperation == "overwrite") { ret = m_refLibrary.UpdateLibraryItemByIDv2_0(pagedata, 0, -1); FolderData folder_data = _ContentApi.GetFolderById(_FolderId); if (folder_data.FolderType == Convert.ToInt32( EkEnumeration.FolderType.Catalog)) { LibraryData library_data = null; library_data = _ContentApi.GetLibraryItemByID(_Id, _FolderId); FileName = library_data.FileName.Substring(System.Convert.ToInt32((library_data.FileName).LastIndexOf("/") + 1)); Ektron.Cms.Commerce.ProductTypeData productTypeData = new Ektron.Cms.Commerce.ProductTypeData(); Ektron.Cms.Commerce.ProductType productType = new Ektron.Cms.Commerce.ProductType(_ContentApi.RequestInformationRef); long xmlConfigurationId = folder_data.XmlConfiguration[0].Id; productTypeData = productType.GetItem(xmlConfigurationId); szPhysicalPath = Server.MapPath(MediaPath); if (productTypeData.DefaultThumbnails.Count > 0) { EkFileIO thumbnailCreator = new EkFileIO(); bool thumbnailResult = false; string sourceFile = (string)(szPhysicalPath + FileName); foreach (ThumbnailDefaultData thumbnail in productTypeData.DefaultThumbnails) { string fileNameNoExtension = FileName.Replace(System.IO.Path.GetExtension(FileName), ""); string fileNameExtension = System.IO.Path.GetExtension(FileName); string thumbnailFile = (string)(szPhysicalPath + "\\" + fileNameNoExtension + thumbnail.Title + fileNameExtension); thumbnailResult = thumbnailCreator.CreateThumbnail(sourceFile, thumbnailFile, thumbnail.Width, thumbnail.Height); } } LibraryData librarydata = new LibraryData(); int iThumbnail = 0; if (productTypeData.DefaultThumbnails.Count > 0) { string sourceFile = (string)(szPhysicalPath + FileName); foreach (ThumbnailDefaultData thumbnail in productTypeData.DefaultThumbnails) { iThumbnail++; string fileNameNoExtension = FileName.Replace(System.IO.Path.GetExtension(FileName), ""); string fileNameExtension = System.IO.Path.GetExtension(FileName); string thumbnailPath = library_data.FileName.Replace(System.IO.Path.GetFileName(library_data.FileName), ""); string thumbnailFile = fileNameNoExtension + thumbnail.Title + fileNameExtension; NewFilename = Strings.Trim(Request.Form["frm_oldfilename"]); librarydata = new LibraryData(); librarydata.Type = "images"; librarydata.FileName = thumbnailPath + thumbnailFile; librarydata.Title = library_data.Title + thumbnail.Title; librarydata.ParentId = _FolderId; librarydata.Id = _Id + iThumbnail; actErrorString = NewFilename; Collection ThumbnailData = new Collection(); ThumbnailData.Add(librarydata.ParentId, "ParentID", null, null); ThumbnailData.Add(librarydata.Id, "LibraryID", null, null); ThumbnailData.Add(librarydata.Type, "LibraryType", null, null); ThumbnailData.Add(librarydata.Title, "LibraryTitle", null, null); ThumbnailData.Add(strContentId, "ContentID", null, null); ThumbnailData.Add(CurrentUserID, "UserID", null, null); ThumbnailData.Add("OverwriteLib", "UpdateLibData", null, null); ThumbnailData.Add(librarydata.FileName, "LibraryFilename", null, null); ThumbnailData.Add(librarydata.OriginalLibraryId, "OriginalLibraryId", null, null); _ContentApi.UpdateLibraryItemByID(ThumbnailData); } } } } else { if (_ContentLanguage == Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES) { _ContentApi.ContentLanguage = _ContentApi.DefaultContentLanguage; } ret = m_refLibrary.AddLibraryItemv2_0(pagedata, 0); // process tag info ProcessTags(Convert.ToInt64( pagedata["LibraryID"]), _ContentApi.ContentLanguage); } if (strOperation.ToLower() == "overwrite") { Response.Redirect("library.aspx?LangType=" + _ContentLanguage + "&action=ViewLibraryItem&id=" + pagedata["LibraryID"] + "&parent_id=" + pagedata["ParentID"] + "&reload=true", false); } else { Response.Redirect((string)("library.aspx?LangType=" + _ContentLanguage + "&action=ViewLibraryByCategory&id=" + _FolderId + "&type=" + strLibType), false); } } catch (Exception ex) { EkException.ThrowException(ex); } }
protected void Page_Load(object sender, System.EventArgs e) { try { _ImageId = long.Parse(Request.QueryString["imageId"]); _ProductTypeData = _ProductType.GetItem(long.Parse(Request.QueryString["productTypeId"])); LibraryData imageData = _ContentApi.GetLibraryItemByID_UnAuth(_ImageId); FolderData folderData = _ContentApi.GetFolderById(imageData.ParentId); if (folderData.PrivateContent == false) { string uploadImagePath = _ContentApi.GetPathByFolderID(_ProductData.Id); //Dim sPhysicalPath As String = Server.MapPath(sWebPath) string sFileName = imageData.FileName.Substring(System.Convert.ToInt32(imageData.FileName.LastIndexOf("/") + 1), System.Convert.ToInt32((imageData.FileName.Length - 1) - imageData.FileName.LastIndexOf("/"))); string sWebPath = imageData.FileName.Replace(sFileName, string.Empty); sWebPath = sWebPath.Replace("//", "/"); string sPhysicalPath = Server.MapPath(imageData.FileName.Replace(sFileName, "")); //Begins: Generate thumbnails. Generates thumbnails for various pixes sizes. if (_ProductTypeData.DefaultThumbnails.Count > 0) { EkFileIO thumbnailCreator = new EkFileIO(); bool thumbnailResult = false; //Dim sourceFile As String = Server.MapPath(_LibraryConfigData.ImageDirectory) & sFileName string sourceFile = Server.MapPath(imageData.FileName); foreach (ThumbnailDefaultData thumbnail in _ProductTypeData.DefaultThumbnails) { string fileNameNoExtension = sFileName.Replace(System.IO.Path.GetExtension(sFileName), ""); string fileNameExtension = System.IO.Path.GetExtension(sFileName); string thumbnailFile = sPhysicalPath + "\\" + "thumb_" + fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension; thumbnailResult = thumbnailCreator.CreateThumbnail(sourceFile, thumbnailFile, thumbnail.Width, thumbnail.Height); //766 load balancing handled by service - no code needed for load balancing _Thumbnails.Add(new ThumbnailData((string) ("thumb_" + fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension), (string) (sWebPath.TrimEnd("/".ToCharArray()) + "/"), fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension, fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension)); } } //Ends : Generate Thumbnails. System.Drawing.Bitmap libraryImage; string libraryPhysicalPath = Server.MapPath(_LibraryConfigData.ImageDirectory); libraryImage = new System.Drawing.Bitmap(Server.MapPath(imageData.FileName)); // Add media image this.litAddMediaJS.Text += "<script type=\"text/javascript\">" + Environment.NewLine; this.litAddMediaJS.Text += " var newImageObj = {" + Environment.NewLine; this.litAddMediaJS.Text += " id: \"" + imageData.Id.ToString() + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " title: \"" + imageData.Title + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " altText: \"" + imageData.Title + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " path: \"" + imageData.FileName.Replace("//", "/") + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " width:" + libraryImage.Width + "," + Environment.NewLine; this.litAddMediaJS.Text += " height:" + libraryImage.Height; int i = 0; if (_Thumbnails.Count > 0) { string sourceFile = sPhysicalPath + sFileName; this.litAddMediaJS.Text += "," + Environment.NewLine; this.litAddMediaJS.Text += " Thumbnails: [" + Environment.NewLine; for (i = 0; i <= _Thumbnails.Count - 1; i++) { this.litAddMediaJS.Text += " {"; this.litAddMediaJS.Text += " title: \"" + _Thumbnails[i].Title + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " imageName: \"" + _Thumbnails[i].ImageName + "\"," + Environment.NewLine; this.litAddMediaJS.Text += " path: \"" + _Thumbnails[i].Path + "\"" + Environment.NewLine; this.litAddMediaJS.Text += " }"; if (i != _Thumbnails.Count - 1) { this.litAddMediaJS.Text += "," + Environment.NewLine; } } this.litAddMediaJS.Text += Environment.NewLine + "] " + Environment.NewLine; } this.litAddMediaJS.Text += "}" + Environment.NewLine; this.litAddMediaJS.Text += "parent.CommerceMediaTabAddLibraryImage(newImageObj);"; this.litAddMediaJS.Text += "</script>"; } else { this.litAddMediaJS.Text += "<script type=\"text/javascript\">" + Environment.NewLine; this.litAddMediaJS.Text += "alert(\'Images in this folder are private and cannot be added to a catalog\');"; this.litAddMediaJS.Text += "</script>"; } } catch (Exception ex) { string reason = ex.Message; } }
protected void btnUpload_Click(object sender, System.EventArgs e) { string parentId = ""; if ((Request.QueryString["catalogid"] != null)&& Request.QueryString["catalogid"] != "") { parentId = Request.QueryString["catalogid"]; } if (txtTitle.Text.IndexOfAny(new char[]{'<','>'}) > -1) { throw (new Ektron.Cms.Exceptions.SpecialCharactersException()); } if (txtAlt.Text.IndexOfAny(new char[]{'<', '>'}) > -1) { throw (new Ektron.Cms.Exceptions.SpecialCharactersException()); } CheckAccess(); try { if (!(fuImage.PostedFile == null)) { // file was sent HttpPostedFile myFile = fuImage.PostedFile; string sFileExt = ""; // Get and check size of uploaded file int nFileLen = myFile.ContentLength; //get and check name and extension string sFileName = myFile.FileName; string sShortName = ""; sFileName = sFileName.Replace("%", ""); if (sFileName.IndexOf("\\") > -1) { string[] aFilename = sFileName.Split('\\'); // take the very last one if (aFilename.Length > 0) { sFileName = aFilename[aFilename.Length - 1]; } } //make safe sFileName = sFileName.Replace(" ", "_").Replace("\'", ""); string[] aFileExt = sFileName.Split('.'); if (aFileExt.Length > 1) { sFileExt = (string) (aFileExt[(aFileExt.Length - 1)].Trim().ToLower()); //use the LAASSTT one. if (sFileExt == "tif" || sFileExt == "bmp") { throw (new Exception("The extension \"" + sFileExt + "\" is not allowed.")); } sShortName = sFileName.Substring(0, System.Convert.ToInt32(sFileName.Length - (sFileExt.Length + 1))); } else { throw (new Exception("The extension \"" + sFileExt + "\" is not allowed.")); } if (aFileExt.Length > 0) { bool bGo = false; for (int i = 0; i <= (aFileExt.Length - 1); i++) { if (sFileExt == aFileExt[i].Trim().ToLower()) { bGo = true; break; } } if (bGo == false) { throw (new Exception("The extension \"" + sFileExt + "\" is not allowed.")); } } else { throw (new Exception("The extension \"" + sFileExt + "\" is not allowed.")); } // Allocate a buffer for reading of the file byte[] myData = new byte[nFileLen + 1]; // Read uploaded file from the Stream myFile.InputStream.Read(myData, 0, nFileLen); //check for existence of file. FileInfo CheckFile; int iUnqueNameIdentifier = 0; string uploadImagePath = _ContentApi.GetPathByFolderID(Convert.ToInt64(parentId)); string sWebPath = (string) (lib_settings_data.ImageDirectory.TrimEnd("/".ToCharArray()) + uploadImagePath.Replace("\\", "/") .Replace(" ", "_") .Replace(".", "") .TrimEnd("/".ToCharArray())); string sPhysicalPath = Server.MapPath(sWebPath); if (! Directory.Exists(sPhysicalPath)) { Directory.CreateDirectory(sPhysicalPath); } CheckFile = new FileInfo(sPhysicalPath + "\\" + sFileName); if (CheckFile.Exists) { while (CheckFile.Exists) { iUnqueNameIdentifier++; sFileName = sShortName + "(" + iUnqueNameIdentifier + ")." + sFileExt; CheckFile = new FileInfo(sPhysicalPath + sFileName); } } //write WriteToFile(sPhysicalPath + "\\" + sFileName, myData); Utilities.ProcessThumbnail(sPhysicalPath, sFileName); //Begins: Generate thumbnails. Generates thumbnails for various pixes sizes. if (_ProductTypeData.DefaultThumbnails.Count > 0) { EkFileIO thumbnailCreator = new EkFileIO(); bool thumbnailResult = false; string sourceFile = sPhysicalPath + "\\" + sFileName; foreach (ThumbnailDefaultData thumbnail in _ProductTypeData.DefaultThumbnails) { string fileNameNoExtension = sFileName.Replace(System.IO.Path.GetExtension(sFileName), ""); string fileNameExtension = System.IO.Path.GetExtension(sFileName); string thumbnailFile = sPhysicalPath + "\\" + "thumb_" + fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension; thumbnailResult = thumbnailCreator.CreateThumbnail(sourceFile, thumbnailFile, thumbnail.Width, thumbnail.Height); //766 load balancing handled by service - no code needed for load balancing _Thumbnails.Add(new ThumbnailData((string) ("thumb_" + fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension), (string) (sWebPath.TrimEnd("/".ToCharArray()) + "/"), fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension, fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension)); } } //Ends : Generate Thumbnails. //upload this file to library. LibraryData librarydata = new LibraryData(); long libraryId = 0; librarydata.FileName = (string) ((sWebPath.Replace("/\\", "\\") + "/" + sFileName).Replace(" ", "_")); librarydata.Type = "images"; if (txtTitle.Text == "") { librarydata.Title = sShortName; } else { librarydata.Title = (string) txtTitle.Text; } librarydata.ParentId = Convert.ToInt64(parentId); libraryId = _ContentApi.AddLibraryItem(ref librarydata); LibraryData retLibraryData = _ContentApi.GetLibraryItemByID(libraryId, Convert.ToInt64(parentId)); //Uploading image to libray ends. System.Drawing.Bitmap imageUpload; imageUpload = new System.Drawing.Bitmap(sPhysicalPath + "\\" + sFileName); // Add media image ltrAddMediaJS.Text += "var newImageObj = {"; ltrAddMediaJS.Text += " id: \"" + libraryId.ToString() + "\","; ltrAddMediaJS.Text += " title: \"" + retLibraryData.Title + "\","; ltrAddMediaJS.Text += " altText: \"" + txtAlt.Text + "\","; ltrAddMediaJS.Text += " path: \"" + librarydata.FileName + "\","; ltrAddMediaJS.Text += " width:" + imageUpload.Width + ","; ltrAddMediaJS.Text += " height:" + imageUpload.Height; int x = 0; if (_Thumbnails.Count > 0) { string sourceFile = sPhysicalPath + sFileName; ltrAddMediaJS.Text += ","; ltrAddMediaJS.Text += "Thumbnails: ["; for (x = 0; x <= _Thumbnails.Count - 1; x++) { ThumbnailData thumbnail = _Thumbnails[x]; string fileNameNoExtension = sFileName.Replace(System.IO.Path.GetExtension(sFileName), ""); string fileNameExtension = System.IO.Path.GetExtension(sFileName); string thumbnailPath = retLibraryData.FileName.Replace(System.IO.Path.GetFileName(retLibraryData.FileName), ""); string thumbnailFile = fileNameNoExtension + thumbnail.Title.Replace("[filename]", "") + fileNameExtension; ltrAddMediaJS.Text += "{"; ltrAddMediaJS.Text += " title: \"" + thumbnail.Title + "\","; ltrAddMediaJS.Text += " imageName: \"" + thumbnail.ImageName + "\","; ltrAddMediaJS.Text += " path: \"" + thumbnail.Path + "\""; ltrAddMediaJS.Text += "}" + Environment.NewLine; if (x != _Thumbnails.Count - 1) { ltrAddMediaJS.Text += "," + Environment.NewLine; } } ltrAddMediaJS.Text += "] " + Environment.NewLine; } ltrAddMediaJS.Text += " }" + Environment.NewLine; ltrAddMediaJS.Text += "parent.Ektron.Commerce.MediaTab.Images.addNewImage(newImageObj);"; //766 LOAD BALANCING HANDLED BY SERVICE //'----------------- Load Balance ------------------------------------------------------ //Dim loadbalance_data As LoadBalanceData() //loadbalance_data = _ContentApi.GetAllLoadBalancePathsExtn(parentId, "images") //If (Not (IsNothing(loadbalance_data))) Then // For j As Integer = 0 To loadbalance_data.Length - 1 // sPhysicalPath = Server.MapPath(loadbalance_data(j).Path) // If (Right(sPhysicalPath, 1) <> "\") Then // sPhysicalPath = sPhysicalPath & "\" // End If // WriteToFile(sPhysicalPath & "\" & sFileName, myData) // Next // 'Begins: Generate thumbnails. Generates thumbnails for various pixes sizes. // If _ProductTypeData.DefaultThumbnails.Count > 0 Then // Dim thumbnailCreator As New EkFileIO // Dim thumbnailResult As Boolean = False // Dim sourceFile As String = sPhysicalPath & "\" & sFileName // For Each thumbnail As ThumbnailDefaultData In _ProductTypeData.DefaultThumbnails // Dim fileNameNoExtension As String = sFileName.Replace(System.IO.Path.GetExtension(sFileName), "") // Dim fileNameExtension As String = System.IO.Path.GetExtension(sFileName) // Dim thumbnailFile As String = sPhysicalPath & "\" & fileNameNoExtension & Replace(thumbnail.Title, "[filename]", "") & fileNameExtension // thumbnailResult = thumbnailCreator.CreateThumbnail(sourceFile, thumbnailFile, thumbnail.Width, thumbnail.Height) // Next // End If // 'Ends : Generate Thumbnails. //End If } else { throw (new Exception("No File")); } } catch (Exception ex) { litError.Text = ex.Message; ltrErrorJS.Text += "justtoggle(document.getElementById(\'dvErrorMessage\'), true);" + Environment.NewLine; } }
public static void ProcessThumbnail(string SrcPath, string SrcFile, int Width, int height, int ThumbSize, string prefix) { string strSrcLoc = ""; string strDesLoc = ""; string strExtn = "png"; bool result = false; try { strSrcLoc = SrcPath + "\\" + SrcFile; strExtn = SrcFile.Substring(SrcFile.Length - 3, 3); strExtn = strExtn.ToLower(); if ("gif" == strExtn) { strExtn = "png"; if (ThumbSize == 0) { strDesLoc = SrcPath + "\\thumb_" + SrcFile.Substring(0, SrcFile.Length - 3) + strExtn; } else { strDesLoc = SrcPath + "\\thumb" + ThumbSize + "_" + SrcFile.Substring(0, SrcFile.Length - 3) + strExtn; } } else { if (ThumbSize == 0) { strDesLoc = SrcPath + "\\thumb_" + SrcFile; } else { strDesLoc = SrcPath + "\\thumb" + ThumbSize + "_" + SrcFile; } } EkFileIO obj = new EkFileIO(); result = obj.CreateThumbnail(strSrcLoc, strDesLoc, Width, height); if (result == false) { throw (new Exception("<p style=\'background-color:red\'>ERROR Initializing: </p>")); } } catch (Exception ex) { throw (new Exception(ex.Message)); } }