Sitefinity CMS

Modifying Content Items Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content > Content Items > Modifying Content Items

Glossary Item Box

Updating content items is a very simple process:

  1. Find the content to be updated
  2. Change its properties (that is, change the name of the content)
  3. Save the content

 

Save the passed content item and its status:

For more information on the status types, see the description of the IContent Interface.
SaveContent(IContent content, ContentStatus status) Copy Code

// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// get all content items
IList listOfContentItems = contentManager.GetContent();

if (listOfContentItems.Count > 0)
{
    // get the first content item
    Telerik.Cms.Engine.IContent firstContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[0]).ID);
    // change the Name meta key
    firstContent.SetMetaData("Name", "Changed Name of Item");
    // save the content item and specify new status of the item
    contentManager.SaveContent(firstContent, Telerik.Cms.Engine.ContentStatus.Draft);

    Response.Write(firstContent.GetMetaData("Name") + "<br />");
}

 

Save the passed content item:

This method is the same as the previous one, except for one difference - the content item status is set so that Published is the default value.
SaveContent(IContent content) Copy Code
// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// get all content items
IList listOfContentItems = contentManager.GetContent();
if (listOfContentItems.Count > 0)
{
   
// get the first content item
   
Telerik.Cms.Engine.IContent firstContent = contentManager.GetContent(((Telerik.Cms.Engine.IContent)listOfContentItems[0]).ID);
   
// change the Name meta key
   
firstContent.SetMetaData("Name", "Changed Name");
   
// save the content item
   
contentManager.SaveContent(firstContent);
   Response.Write(firstContent.GetMetaData(
"Name") + "<br />");
}

 

See Also