Sitefinity CMS

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

Glossary Item Box

There are three methods for creating a content item:

 

Create content item with specified MIME type:

CreateContent(string mimeType) Copy Code
// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// create an empty content
Telerik.Cms.Engine.IContent newContent = contentManager.CreateContent("text/html");
// save the initial content properties
// note that properties such as ID are automatically
// set by Sitefinity. This however does not mean that you cannot
// change them
newContent.Content = "My first content ... some text";
// set meta keys for the content item
newContent.SetMetaData("Name","Content Item 1 Name");
newContent.SetMetaData(
"Author", "author name");
newContent.SetMetaData(
"Description","Some info about the content item.");
//save the content
contentManager.SaveContent(newContent);

 

 Create content item with specified MIME type and ID of the content item:

CreateContent(string mimeType, Guid id) Copy Code
// create new instance of ContentManager
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager();
// just for demonstration - create Guid number
Guid contentID = new Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8");
// create an empty content
Telerik.Cms.Engine.IContent newContent = contentManager.CreateContent("text/html", contentID);
// save the initial content properties
// note that properties such as ID are automatically
// set by Sitefinity. This however does not mean that you cannot
// change them
newContent.Content = "My second content ... some text";
// set meta keys for the content item
newContent.SetMetaData("Name","Content Item 2 Name");
newContent.SetMetaData(
"Author", "author name");
newContent.SetMetaData(
"Description","Some info about the content item.");
//save the content
contentManager.SaveContent(newContent);

 

See Also