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; }