Tuesday, May 1, 2007

Hiding the SharePoint blog admin links

When you're setting up a SharePoint public blog site where users don't need the blogs admin links you are pretty much stuck with nothing but a hack. Now why would you want to hide the admin links: it could be many reasons from simplicity to the fact that your users don't need those links since their security settings doesn't permit them to do anything with them. I've had this experience when developing a public blogging site for a news agency. They wanted their users to be able to create a blog, post to their own blog but not be able to edit/modify/approve/reject comments or be able to approve/reject blogs. Now all this can be setup with SharePoint's security features but anyone with Contribute access will get to see the admin links (but won't be able to do much with them). Now since this will be extremely annoying you would want to remove it from a public site.

One of two solutions can be used to achieve this you either have to modify the default.aspx page that exists in each blog using SharePoint designer. This solution is too much work and would hinder other future changes that you need to make to all blogs (since you have to go and change every default.aspx page again).

The second solution is to create a WebPart, put it on the default.aspx file that exists in the templates directory under the blog template site. This WebPart can scan the page and find the AdminLinks WebPart and then hide it:

protected override void OnPreRender(EventArgs e)


Control blogadmin = RecursiveFindControl(Page);

if (blogadmin != null) //hide the control

((Microsoft.SharePoint.WebPartPages.BlogAdminWebPart)blogadmin).Hidden = true;


private Control RecursiveFindControl(Control control)


foreach (Control c in control.Controls)


if (c is Microsoft.SharePoint.WebPartPages.BlogAdminWebPart)

return c;

if (c.HasControls())


Control rc = RecursiveFindControl(c);

if (rc != null)

return rc;



return null;


No comments: