Sitefinity CMS

Managing Posts Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content Based Modules > Blogs > Post Items > Managing Posts

Glossary Item Box

Most of the methods available in the ContentManager class could be used to manage blog posts. For more information on how to work with the ContentManager methods, see Generic Content API Overview of Generic Content API.

 

This topic will provide two examples to demonstrate how to use the BlogManager class and manage post items while at the same time applying ContentManager methods.

 

 Create a blog post:

Copy Code
// create new instance of BlogManager
Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
// get all blogs
IList listOfAllBlogs = blogManager.GetBlogs();
if (listOfAllBlogs.Count > 0)
{
   
// get the first blog item
   
Telerik.Blogs.IBlog firstBlog = blogManager.GetBlog(((Telerik.Blogs.IBlog)listOfAllBlogs[0]).ID);
   
// create a blog post by calling the CreateContent method of the
   
// ContentManager class through the BlogManager class
   
Telerik.Cms.Engine.IContent postContent = blogManager.Content.CreateContent("text/html");


   
// set the parent of the post item to be firstBlog
   
postContent.ParentID = firstBlog.ID;
   
// save the Content property value and the Title meta key
   
postContent.Content = "My first Post Item includes ...";
   postContent.SetMetaData(
"Title", "My Post Item 1");
   
//save the Content item through the BlogManager
   
blogManager.Content.SaveContent(postContent);

   Response.Write(firstBlog.Name +
" has following content : " + postContent.Content + "<br />");
}

 

Although BlogManager uses ContentManager class methods for the post items, which includes GetMetaData and SetMetaData, the Blogs module has specific meta keys which differ from the Generic Content ones. This means that when using the two methods for meta keys, you should use the Blogs meta keys. Here they are:

  • Title
  • Author
  • Publication_Date
  • BlogID
  • Category

 

Get all content for the current Blogs provider:

Copy Code
// create new instance of BlogManager
Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
// get all blog posts
IList listOfPosts = blogManager.Content.GetContent();
if (listOfPosts.Count > 0)
{
   
foreach (Telerik.Cms.Engine.IContent newsItem in listOfPosts)
       Response.Write(newsItem.GetMetaData(
"Title") + "<br />");
}

 

Apart from the methods that could be used from the ContentManager class, there are several more methods for managing blog posts, and they are provided only in the BlogManager class. Here they are: 

  • GetPosts(string sortExp, params Guid[] blogIds) - Get all posts for given blogs, sorted. OBSOLETE!

  • GetPosts(string sortExp, Guid[] blogIds, params IMetaSearchInfo[] filter) - Get filtered subset of posts for given blogs, sorted. OBSOLETE!

    See Also