Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > What is the right way to work with Blogs programmatically View modes: 
User avatar
Member
Member
bogdan - 3/26/2009 1:11:39 PM
   
What is the right way to work with Blogs programmatically
Hi all,

I'm new to Kentiko API, and have a stupid question:

In the Developer's Guide, one can read "Since the blog posts are standard Kentico CMS documents, you can create, modify, read and delete them using standard API for documents."

Ok, let's do it like this


// create tree provider instance
CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);

// get parent node for new document
CMS.TreeEngine.TreeNode parent = provider.SelectSingleNode(CMS.CMSHelper.CMSContext.CurrentSite.SiteName,
blogPath,
CMS.TreeEngine.TreeProvider.ALL_CULTURES);

// create a new tree node
CMS.TreeEngine.TreeNode node = new CMS.TreeEngine.TreeNode("CMS.BlogPost", provider);

if (parent != null)
{
// set document properties
node.NodeName = title;
node.NodeAlias = title;
node.DocumentTags = tags;
node.SetValue("BlogPostTitle", title);
node.SetValue("BlogPostSummary", summary);
node.SetValue("BlogPostBody", body);
node.SetValue("BlogPostDate", DateTime.Now);
node.SetValue("BlogPostAllowComments", true);

node.DocumentCulture = "ru-ru";
// create New document
node.Insert(parent.NodeID);

}


This code works, but it inserts a new blog post directly into the Blog directory (in my case blogPath = "/Blogs")

Well, it is not exactly that I expected, because usually (when you create new blog entry from CMSDesk) it first creates a Month, then posts the blog entry into the Month.

I know that I could probably write this logic myself, i.e. check if there is no related Month in the Blog folder, first create new Document for the month, then select this month as a parent node and insert a blog record here

Perhaps writing such a code is not a very complicated task.

But, this logic should be already implemented somewhere inside Kentico codebase, and I probably there is a helper that inserts into CONTENT_BlogMonth and does all routine work in this case.

Could anybody tell me, what is the recommended way to work with Blog posts thru Kentiko API ?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/27/2009 4:10:01 PM
   
RE:What is the right way to work with Blogs programmatically
Hi,

The automatic adding of the month document is additional task according to the document creation. Someone wants to use it, someone not. It is not hard to achieve this. You can take inspiration here: \CMSDesk\Content\edit.aspx.cs. There is little bit more of other code, but the code is commented so it is easy to find it.

Best Regards,
Juraj Ondrus