Create a news item with the Native API

Use the code example below to create a news item and to set its Title and Content with the Native API.

In the example below, you perform the following:

  1. Define the language culture of the news item.
  2. Get an instance of the NewsManager class.
  3. Set the properties of the news item object.
  4. Set the state to the news item to published.
  5. Save the changes with the news manager.

Create a news item with the Native API

C#
public static void CreateNewsItemNativeApi(string newsTitle, string newsContent, CultureInfo culture)
{
   //Define the culture of the news item
   using (new CultureRegion(culture))
   {
       NewsManager newsManager = NewsManager.GetManager();
       var newsItem = newsManager.CreateNewsItem();
       
       //Set the properties of the news item.
       newsItem.Title = newsTitle;
       newsItem.Content = newsContent;
       
       //Recompiles and validates the url of the news item.
       newsManager.RecompileAndValidateUrls(newsItem);
       //Set the news item to state publish.
       newsItem.ApprovalWorkflowState = ApprovalStatusConstants.Published;
       newsManager.Lifecycle.Publish(newsItem);
       //Save changes with the manager.
       newsManager.SaveChanges();
   }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?