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 ?