Adding “Recent Blog Post” web part programatically


This is a very basic post.  I really couldn’t find any post that could tell me how to add “Recent Blog Posts” web part using object modal.

The “Recent Blog Posts” web part is added by default on the SharePoint 2010 My Sites.  I was just wondering if we can add that using the SharePoint Object Modal.

I found out that adding a recent blog posts web part is really simple:-

// Get the web part collection
SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(“default.aspx”, PersonalizationScope.Shared);

Microsoft.SharePoint.Portal.WebControls.BlogView wpBlogView = new BlogView();
/*This Is very important.  Make sure To Link To the xsl file*/
wpBlogView.XslLink = “blog.xsl”;
wpBlogView.Title = “Recent Blog Posts”;

wpManager.AddWebPart(wpBlogView, “WebPartZone”, 0);

Hope this helps some one in need 🙂 

Regards,

Sudhir


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s