Working With Blogs API

  • Updated

There is currently no framework manager API for Blogs so using the legacy APIs is appropriate.  Here are some code samples for working with the Blogs API.

Add Blog:

Ektron.Cms.API.Content.Blog bapi = new Ektron.Cms.API.Content.Blog(); 
long folderid = 0; //where to add the blog 
bool allowcomments = true; 
bool moderatecomments = false; 
bool requireauth = false; 
Ektron.Cms.BlogRoll rolllinks = new Ektron.Cms.BlogRoll(); 
long blogid = bapi.AddBlog(folderid, "Blog Name", "Blog Title", "blog description", Ektron.Cms.Common.EkEnumeration.BlogVisibility.Public, allowcomments, moderatecomments, requireauth, categories, rolllinks);

Add Blog Post:
Ektron.Cms.ContentData postdata = new Ektron.Cms.ContentData(); 
string[] categories = { "test", "test1" }; 
long postid = bapi.AddPost(blogid, postdata, categories, false, "Tags, Tags2", "");
Add Blog Comment:
Ektron.Cms.API.User.User uapi = new Ektron.Cms.API.User.User(); 
Ektron.Cms.UserData ud = uapi.GetUser(uapi.UserId, false, false); 
Ektron.Cms.BlogComment bc = new Ektron.Cms.BlogComment(); 
bc.DateCreated = DateTime.Now; 
bc.DisplayName = ud.DisplayName; 
bc.Email = ud.Email; 
bc.Message = "Test Message"; 
bc.Title = "Title"; 
bc.UserID = ud.Id; 
bc.PostID = postid; 
bool result = bapi.AddCommentForPost(bc); //success = false 
Get Blog Comments:
Ektron.Cms.Framework.Settings.TaskManager tmgr = new Ektron.Cms.Framework.Settings.TaskManager(); 
Ektron.Cms.TaskCriteria criteria = new Ektron.Cms.TaskCriteria(); 
criteria.AddFilter(Ektron.Cms.Common.TaskProperty.ContentId, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, 427); 
criteria.PagingInfo = new Ektron.Cms.PagingInfo(1000); 
var tData = tmgr.GetList(criteria);      
    foreach (var item in tData)      
    {      
     Response.Write(item.Description);      
    } 

    Other Blog Functions:      


bapi.DeleteBlog(blogid);      
    bapi.DeleteBlogPostComment(postcommentid);      

    int maxentries = 5; //max number of results to return      
    int languageid = 1033;      

    Ektron.Cms.BlogData bdata = bapi.GetBlog(blogid, "Start Date", maxentries, languageid);      
    bdata = bapi.GetBlogData(blogid);      
    bdata = bapi.GetBlogDataForPost(postid);      

    Ektron.Cms.BlogPostData bpd = bapi.GetBlogPostData(postid);      
    bapi.GetBlogRoll(blogid); //get the blog roll      
    postdata = bapi.GetPost(postid, ref bpd); //get a post with info      
    bpd = bapi.GetPostbyID(postid); //get a blog post      
    bapi.GetUserBlog(ud.Id); //get the blog for a user id      
    bapi.UpdateBlogProperties(bdata); //change properties in blog data and resave