Sitefinity CMS

News API Walkthrough Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content Based Modules > News > News API Walkthrough

Glossary Item Box

Most of the methods available in the ContentManager class could be used to manage news items. 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 NewsManager class and manage news items while at the same time applying ContentManager methods.

 

 Create a news item:

Copy Code
// create new instance of NewsManager
Telerik.News.NewsManager newsManager = new Telerik.News.NewsManager("News");
// create a news content item by calling the CreateContent method of the
// ContentManager class through the NewsManager class
Telerik.Cms.Engine.IContent newsContent = newsManager.Content.CreateContent("text/html");
// save the Content property value, and the Title meta key
newsContent.Content = "My first News Item";
newsContent.SetMetaData(
"Title", "News 1");
//save the Content item through the NewsManager
newsManager.Content.SaveContent(newsContent);
Response.Write(newsContent.Content +
"<br />");

 

Although NewsManager uses ContentManager class methods, which includes GetMetaData and SetMetaData, the News 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 News meta keys. Here they are:

  • Title
  • Summary
  • Author
  • Source
  • Publication_Date
  • Expiration_Date
  • Thumbnail
  • Category

 

Get all content for the current News provider:

GetContent() Copy Code
// create new instance of NewsManager
Telerik.News.NewsManager newsManager = new Telerik.News.NewsManager("News");
// get all news content items
IList listOfNewsItems = newsManager.Content.GetContent();
if (listOfNewsItems.Count > 0)
{
 
foreach(Telerik.Cms.Engine.IContent newsItem in listOfNewsItems)
     Response.Write(newsItem.GetMetaData(
"Title") + "<br />");
}

 

See Also