Retrieving All Blog Posts from Kentico CMS's API

Kentico CMS is a powerful web content solution, highly customizable though a web interface. My personal favorite feature is its open API allowing you to create your own .Net based controls, modules and event handlers. The one flaw I find in the API is its poor documentation. I wanted to get all blog posts from all blogs on my test site. I quickly found the Method CMS.Blogs.BlogHelper.GetAllPosts(), however that is about all the CMS was good for, it provided no examples or more explicit details on usage other than what params the function accepted. I was left on my own to find out what each param did and what it should be.

Site Name was easy enough, what the site I created is named in the CMS Site Manager, in my case, "SRT".

The AliasPath through me off though, I had no clue what this should be, all I knew is I wanted it to return all posts. I found out that the alias path is the URL path to your blog. So http://localhost/KenticoCMS/Blogs/Blog-1.aspx has the alias of '/Blogs/Blog-1'. You can however use the wildcard '%' to return posts from all blogs, as I have.

The culture code would be useful if you are hosting a community site and would like to serve up only certain cultured items, In my test example I only have en-US cultured documents so I set this to "en-US" I also set combineWithDefaultCulture to true, this wont effect my results of retrieving my posts since the default culture on my site is "en-US"

Where and OrderBy threw me  a bit, I tried using standard SQL like "NodeID = 14" but everything seems to be throwing errors here. I will just handle any sorting/filtering I wish to do with LINQ once I have the dataset. After the error was thrown I was able to see the SQL statement created by this function, which I think I will manipulate and use on my own instead of the function in the future.  Query: SELECT * FROM View_CONTENT_Blog_Joined WHERE ((((SiteName = N'SRT') AND (Published = 1)) AND ((DocumentCulture = N'') OR (DocumentCulture = N'en-US'))) AND (NodeID = 14)) ORDER BY 1. So all of this content is coming from the View_CONTENT_Blog_Joined view.

 And finally I only wanted to aggregate published posts so I set Published = true.

 

I ended up with this: BlogHelper.GetBlogPosts("SRT", "%", "", true, "", "", true); This will return only one table named 'cms.blogpost'.

 

 A small SQL script I wrote that will give me only the informaion I need and the username/Full Name of the post creator is as follows:

SELECT FullName,UserID,UserName,NodeAliasPath,DocumentName,DocumentCreatedWhen,BlogPostBody,BlogPostSummary from KenticoCMS.dbo.CMS_User as U INNER JOIN KenticoCMS.dbo.View_CONTENT_BlogPost_Joined as BlogPost on BlogPost.DocumentCreatedByUserID = U.UserID;

You can add sort and where clauses as you see fit to filter through the mess, but I wanted everything in the database.

Published 27 May 2009 06:31 AM by cmsears
Filed under:
Ads by Lake Quincy Media

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)