This article shows a sample and describes the steps to leverage the ContentManager to programmatically add new language versions of content for existing content items in the CMS retaining the same ID.
1. Call the ContentManager.GetItem to pull the existing content item in the current language.
2. Instantiate a new ContentManager in the language of interest.
3. Update the original ContentData object with new language from the GetItem return result.
4. Call the ContenManager.Add with modified content objecct with the second ContentManager.
5. The content will be added with the same ID as the original.
The sample is included below.
protected void uxSubmit_Click(object sender, EventArgs e)
{
try
{
long contentID = long.Parse(uxContentId.Text);
ContentManager contentManager = new ContentManager(Ektron.Cms.Framework.ApiAccessMode.Admin);
ContentData cData = contentManager.GetItem(contentID);
if (cData != null && cData.Id > 0)
{
ContentManager langCM = new ContentManager(Ektron.Cms.Framework.ApiAccessMode.Admin);
langCM.ContentLanguage = 1034;
cData.LanguageId = 1034; // update the original content data's language
ContentData langContentData = langCM.Add(cData); // this will add the content with the same id but different language
MessageUtilities.UpdateMessage(uxMessage, "Lanaguage version had been added. originalID: " + cData.Id + " newID: " + langContentData.Id, Message.DisplayModes.Success);
}
else
{
uxStatus.Visible = true;
MessageUtilities.UpdateMessage(uxMessage, "Invalid content ID ", Message.DisplayModes.Error);
return;
}
}
catch (Exception ex)
{
MessageUtilities.UpdateMessage(uxMessage, ex.Message, Message.DisplayModes.Error);
}
}
Please sign in to leave a comment.