private void Page_Load(System.Object sender, System.EventArgs e) { try { bool fileChanged = true; string assetId; List<AssetFileData> assetIdFileNameList = null; List<AssetFileData> tempAssetIdFileNameList = new List<AssetFileData>(); m_refContent = AppUI.EkContentRef; if (Request.Form["type"] != null) { actionType = (string)(Request.Form["type"].Trim().ToLower()); } if (Request.Form["requireMetaTaxonomy"] != null) { isCallerDmsDragDropCtl = true; } m_refContApi = new ContentAPI(); m_refMsg = m_refContApi.EkMsgRef; if (!String.IsNullOrEmpty(Request.Form["content_language"])) { ContentLanguage = Convert.ToInt32(Request.Form["content_language"]); if (ContentLanguage == Ektron.Cms.Common.EkConstants.CONTENT_LANGUAGES_UNDEFINED || ContentLanguage == Ektron.Cms.Common.EkConstants.ALL_CONTENT_LANGUAGES) { ContentLanguage = AppUI.DefaultContentLanguage; } AppUI.ContentLanguage = ContentLanguage; m_refContApi.ContentLanguage = ContentLanguage; } if (actionType.ToLower() == "add" && (Request.QueryString["SelTaxonomyId"] != null) && Request.QueryString["SelTaxonomyId"] != "") { TaxonomySelectId = Convert.ToInt64(Request.QueryString["SelTaxonomyId"]); } userId = Convert.ToInt64(Ektron.Cms.CommonApi.GetEcmCookie()["user_id"]); loginToken = Convert.ToInt32(Ektron.Cms.CommonApi.GetEcmCookie()["unique_id"]); if ((Request.Form["taxonomyselectedtree"] != null) && Request.Form["taxonomyselectedtree"].ToString().Length > 1) { jsTaxonomyIdReloadFrame.Text = Request.Form["taxonomyselectedtree"].ToString(); if (Request.Form["taxonomyselectedtree"].ToString().Split(",".ToCharArray()) != null) { jsTaxonomyId.Text = (Request.Form["taxonomyselectedtree"].ToString().Split(",".ToCharArray()))[0]; } } if (Request.Form["editaction"] == "cancel") { Session.Remove(Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"); if ((actionType != "add") && (Request.Form["content_id"] != "" && Convert.ToInt64(Request.Form["content_id"]) > 0)) { string status = m_refContApi.GetContentStatusById(Convert.ToInt64(Request.Form["content_id"])); if (status.ToLower() == "o") //28710 - if asset is a office file status = "A" on saving in word { m_refContent.UndoCheckOutv2_0(Convert.ToInt64(Request.Form["content_id"])); } if (Request.Form["FromEE"] == "true" || Request.QueryString["close"] == "true") { if (Request.QueryString["close"] == "true") { Response.Redirect("close.aspx?reload=true", false); return; } else { Response.Redirect("close.aspx", false); return; } } else { Response.Redirect((string)("content.aspx?id=" + Request.Form["content_id"] + "&action=viewstaged&LangType=" + m_refContApi.ContentLanguage), false); return; } } else { if (Request.Form["FromEE"] == "true" || Request.QueryString["close"] == "true") { if (Request.QueryString["close"] == "true") { Response.Redirect("close.aspx?reload=true", false); return; } else { Response.Redirect("close.aspx", false); return; } } else { Response.Redirect((string)("content.aspx?id=" + Request.Form["content_folder"] + "&action=ViewContentByCategory&LangType=" + m_refContApi.ContentLanguage), false); return; } } } int i; for (i = 0; i <= m_AssetInfoKeys.Length - 1; i++) { asset_info.Add(m_AssetInfoKeys[i], ""); } if (actionType != "multiple,add") { if ((Request.Form["asset_assetid"] != null) && (Request.Form["asset_assetid"].Length > 1)) { assetId = Request.Form["asset_assetid"]; } else { assetId = System.Guid.NewGuid().ToString(); } Response.Expires = -1; Response.AddHeader("Pragma", "no-cache"); Response.AddHeader("cache-control", "no-store"); string ErrDescription = ""; string filename; if (Request.Files["fileupload"] != null) { fileChanged = true; filename = Request.Files["fileupload"].FileName; string[] DMSFileTypes = DocumentManagerData.Instance.FileTypes.Replace("*","").Split(','); bool IsFileTypeAllowed = false; if (DMSFileTypes != null && !string.IsNullOrEmpty(filename)) { if (Array.FindIndex(DMSFileTypes, x => x.ToString().Trim().ToLower() == filename.Substring(filename.IndexOf(".")).ToLower()) >= 0) { IsFileTypeAllowed = true; } } if (actionType == "add") { Ektron.ASM.AssetConfig.AssetData astData = new Ektron.ASM.AssetConfig.AssetData(); astData = m_refContent.GetAssetDataBasedOnFileName(Path.GetFileName(filename), Convert.ToInt64(Request.Form["content_folder"]), -1); if (astData != null && astData.ID != "" && astData.Name != "") { ErrDescription = "A content with title: " + astData.Name + " and ID: " + astData.ID + " already exists with the file name: " + Path.GetFileName(filename) + ". Please use a different filename."; Response.Redirect((string)("reterror.aspx?info=" + ErrDescription), false); return; } } if (filename.Trim() == "") { fileChanged = false; filename = (string)(Request.Form["oldfilename"].ToString()); } else { if (!IsFileTypeAllowed) { EkException.LogException(String.Format("Attempt at uploading unallowed file type occurred from user id: {0}", this.userId)); ErrDescription = "The file has not been uploaded. Please see administrator."; Response.Redirect("reterror.aspx?info=" + ErrDescription, false); return; } try { string docFilePath = DocumentManagerData.Instance.WebSharePath; if (!System.IO.Path.IsPathRooted(docFilePath)) { docFilePath = Ektron.ASM.AssetConfig.Utilities.UrlHelper.GetAppPhysicalPath() + docFilePath; } string destFileName = docFilePath + Path.GetFileName(filename) + assetId; using (BinaryReader br = new BinaryReader(Request.Files["fileupload"].InputStream)) { byte[] buf; using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(destFileName, FileMode.Create))) { buf = br.ReadBytes(bufSize); if (EkFunctions.IsImage(Path.GetExtension(filename))) { System.IO.Stream streamTmp=new System.IO.MemoryStream(buf); if (!EkFunctions.isImageStreamValid(streamTmp)) { streamTmp.Flush(); streamTmp.Close(); throw new Exception("The image is corrupted or not in correct format."); } streamTmp.Flush(); streamTmp.Close(); } int index = 0; while (buf.Length > 0) { binaryWriter.Write(buf, 0, buf.Length); index += buf.Length; buf = br.ReadBytes(bufSize); } binaryWriter.Flush(); binaryWriter.Close(); } br.Close(); } } catch (Exception ex) { throw ex; } } } else { filename = (string)(Request.Form["filename"].ToString()); fileChanged = false; } ProcessPage(filename, assetId, fileChanged, null); } else { bool isOfc2010 = false; if (Request.Cookies[DMSCookieName] != null && !string.IsNullOrEmpty(Request.Cookies[DMSCookieName].Value)) { if (Request.Cookies[DMSCookieName].Value == "2010") { isOfc2010 = true; } } if (isOfc2010) { ProcessUploadOffice2010(); } else { #region originalupload if (Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"] != null) { assetIdFileNameList = (List<AssetFileData>)Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"]; Session.Remove(Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"); } //If coming from photo/image gallery, do not upload any files if a single invalid file is found if ((Request.Form["isImage"] != null) && Request.Form["isImage"].ToString() == "1") { List<string> allFilesList = null; if (Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "AllPostedFiles"] != null) { allFilesList = (List<string>)Session[userId + loginToken + "AllPostedFiles"]; Session.Remove(Convert.ToString(userId) + Convert.ToString(loginToken) + "AllPostedFiles"); } string invalidFilesMsg = ""; if (allFilesList != null) { for (int index = 0; index <= allFilesList.Count - 1; index++) { if (!EkFunctions.IsImage(Path.GetExtension(System.Convert.ToString(allFilesList[index])))) { invalidFilesMsg = System.Convert.ToString(allFilesList[index]); this.jsInvalidFiles.Text = "Only images can be uploaded here, invalid file type found: " + invalidFilesMsg.Replace("\\", "\\\\").Replace("\'", "\\\'") + "\\nNo images have been uploaded."; this.uxAlertInvalidFileType.Visible = true; this.uxCloseThickBox.Visible = true; return; } } } } if (assetIdFileNameList != null && assetIdFileNameList.Count > 0) { for (int index = 0; index <= assetIdFileNameList.Count - 1; index++) { if (assetIdFileNameList[index].FileName.IndexOfAny(new char[] { '&', '%', '+' }) > -1) { this.jsInvalidFiles.Text = "Some files with &,+ or % could not be uploaded"; this.uxAlertInvalidFileType.Visible = true; } else { tempAssetIdFileNameList.Add(assetIdFileNameList[index]); } } assetIdFileNameList = tempAssetIdFileNameList; } fileChanged = true; if ((assetIdFileNameList != null) && assetIdFileNameList.Count > 0) { ProcessPage("", "", true, assetIdFileNameList); } else { //if any files were rejected if (Request.Form["FromEE"] == "true" || Request.QueryString["close"] == "true") { if (Request.QueryString["close"] == "true") { Response.Redirect("close.aspx?reload=true", false); } else { Response.Redirect("close.aspx", false); } } else { if (isCallerDmsDragDropCtl == true) { if ((Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"] != null) && Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"].ToString() != "") { this.jsInvalidFiles.Text = m_refMsg.GetMessage("lbl error message for multiupload") + " " + Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"].ToString().Replace("\\", "\\\\").Replace("\'", "\\\'"); this.jsInvalidFiles.Text += "\\n" + m_refMsg.GetMessage("js:cannot add file with add and plus"); this.uxAlertInvalidFileType.Visible = true; Session.Remove(Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"); this.uxCloseThickBox.Visible = true; } else { Response.Redirect(Request.UrlReferrer.PathAndQuery + ((Request.UrlReferrer.PathAndQuery.IndexOf("showtab") > -1) ? "" : "&showtab=multiple"), false); } } else { if ((Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"] == null) || Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "RejectedFiles"].ToString() == "") { if ((Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"] == null) || Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "Attachments"].ToString() == "") { if (Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "NoFilesToUpload"] == null) { Session.Add(Convert.ToString(userId) + Convert.ToString(loginToken) + "NoFilesToUpload", "NoFilesToUpload"); } else { Session[Convert.ToString(userId) + Convert.ToString(loginToken) + "NoFilesToUpload"] = "NoFilesToUpload"; } } } Response.Redirect((string)("content.aspx?id=" + Request.Form["content_folder"] + "&action=ViewContentByCategory&LangType=" + ContentLanguage), false); } } } #endregion } } } catch (Exception ex) { Utilities.ShowError(ex.Message.ToString()); } }
private bool PublishContent() { ContentAPI contApi = new ContentAPI(); EkContent contObj; int ContentLanguage = EkConstants.CONTENT_LANGUAGES_UNDEFINED; if (!(Page.Request.QueryString["LangType"] == null)) { if (Page.Request.QueryString["LangType"] != "") { ContentLanguage = Convert.ToInt32(Page.Request.QueryString["LangType"]); contApi.SetCookieValue("LastValidLanguageID", ContentLanguage.ToString()); } else { if (contApi.GetCookieValue("LastValidLanguageID") != "") { ContentLanguage = Convert.ToInt32(contApi.GetCookieValue("LastValidLanguageID")); } } } else { if (contApi.GetCookieValue("LastValidLanguageID") != "") { ContentLanguage = Convert.ToInt32(contApi.GetCookieValue("LastValidLanguageID")); } } if (ContentLanguage == EkConstants.CONTENT_LANGUAGES_UNDEFINED) { contApi.ContentLanguage = EkConstants.ALL_CONTENT_LANGUAGES; } else { contApi.ContentLanguage = ContentLanguage; } object[] acMetaInfo = new object[4]; string MetaSelect; string MetaSeparator; string MetaTextString = ""; int ValidCounter = 0; int i = 0; bool hasMeta = false; if (Page.Request.Form["frm_validcounter"] != "") { ValidCounter = System.Convert.ToInt32(Page.Request.Form["frm_validcounter"]); hasMeta = true; } else { ValidCounter = 1; } string TaxonomyTreeIdList = ""; TaxonomyTreeIdList = Page.Request.Form[taxonomyselectedtree.UniqueID]; if ((!string.IsNullOrEmpty(TaxonomyTreeIdList)) && TaxonomyTreeIdList.Trim().EndsWith(",")) { ltrTaxonomyTreeIdList.Text = TaxonomyTreeIdList.Substring(0, TaxonomyTreeIdList.Length - 1); } contObj = contApi.EkContentRef; string[] ids; string contId = ""; ids = m_idString.Split(",".ToCharArray()); htImagesAssets = new System.Collections.Hashtable(); foreach (string tempLoopVar_contId in ids) { contId = tempLoopVar_contId; if (contId != "") { EditUrlAlias(long.Parse(contId),this.m_folderId); page_meta_data = new Collection(); if (hasMeta == true) { for (i = 1; i <= ValidCounter; i++) { acMetaInfo[1] = Page.Request.Form["frm_meta_type_id_" + i]; acMetaInfo[2] = contId; MetaSeparator = Page.Request.Form["MetaSeparator_" + i]; MetaSelect = Page.Request.Form["MetaSelect_" + i]; if (Convert.ToInt32(MetaSelect) != 0) { MetaTextString = Strings.Replace(Page.Request.Form["frm_text_" + i], ", ", MetaSeparator.ToString(), 1, -1, 0); if (MetaTextString.StartsWith(MetaSeparator)) { MetaTextString = MetaTextString.Substring(MetaTextString.Length - (MetaTextString.Length - 1), (MetaTextString.Length - 1)); } MetaTextString = CleanString(MetaTextString); acMetaInfo[3] = MetaTextString; } else { MetaTextString = Strings.Replace(Page.Request.Form["frm_text_" + i], ";", MetaSeparator.ToString(), 1, -1, 0); if (MetaTextString == null) MetaTextString = ""; MetaTextString = CleanString(MetaTextString); acMetaInfo[3] = MetaTextString; } page_meta_data.Add(acMetaInfo, i.ToString(), null, null); acMetaInfo = new object[4]; } } if (!(string.IsNullOrEmpty(TaxonomyTreeIdList))) { TaxonomyContentRequest request = new TaxonomyContentRequest(); request.ContentId = long.Parse(contId); request.TaxonomyList = TaxonomyTreeIdList; request.FolderID = m_folderId; contObj.AddTaxonomyItem(request); } if (page_meta_data.Count > 0 && hasMeta == true) { m_ContentApi.EkContentRef.UpdateMetaData(page_meta_data); } } } foreach (string tempLoopVar_contId in ids) { contId = tempLoopVar_contId; if (contId != "") { try { string Status; Status = (string)(contApi.GetContentStatusById(long.Parse(contId))); long lcontId=long.Parse(contId); if (htImagesAssets[lcontId] != null)// if item is exists in the hash table, the url alias is required. {//process url alias required, publish image assets, checkin others bool bIsPublish = (bool)htImagesAssets[lcontId]; if (Status == "O") { if (bIsPublish) contApi.PublishContentById(lcontId, m_folderId, ContentLanguage, "true", -1, ""); else contApi.EkContentRef.CheckIn(lcontId, ""); } else if (Status == "I") { if(bIsPublish) contApi.EkContentRef.SubmitForPublicationv2_0(lcontId, m_folderId, string.Empty); } } else {// normal process if (Status == "O") // this will check in and publish { contApi.PublishContentById(lcontId, m_folderId, ContentLanguage, "true", -1, ""); } else if (Status == "I") // this is just a publish { contApi.EkContentRef.SubmitForPublicationv2_0(lcontId, m_folderId, string.Empty); } } } catch (Exception) { // I wrapped it in this try block because there is a current problem on the server where the content is already being put // into published state if there are multiple pieces of content, the metadata still updates and is put in the right state. } } } return true; }