Answers for "Kentico 9 - Updating blog posts"

C#
0

Kentico 9 - Updating blog posts

// Prepares a TreeProvider instance
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Gets all published blog posts under "/Blogs/NewBlog" as a DataSet
DataSet posts = BlogHelper.GetBlogPosts(SiteContext.CurrentSiteName, "/Blogs/NewBlog", null, true, null, null, true);

if (!DataHelper.DataSourceIsEmpty(posts))
{
    // Loops through individual blog posts in the DataSet
    foreach (DataRow postDr in posts.Tables[0].Rows)
    {
        // Creates a page object from the DataRow
        TreeNode modifyPost = TreeNode.New("cms.blogpost", postDr, tree);

        // Updates the blog post properties
        modifyPost.SetValue("BlogPostBody", "The blog post body was updated.");

        // Saves the updated blog post to the database
        modifyPost.Update();
    }
}
Posted by: Guest on June-25-2021

C# Answers by Framework

Browse Popular Code Answers by Language