SharePoint: Show Ribbon by Default

by Danielvg 11. July 2010 10:53

While working on a project at work I got a Bug work item that said “Ribbon is not shown by default when a new web is created”. Long story short the project involves a custom way of creating new webs in SharePoint, the webs are based on a publishing web but the Ribbon is not shown when the web is created and the users have to click “show Ribbon” which is not desired.

Sadly google/bing was no help so I had to turn to some Javascript debug and reflector to solve to problem. It got me to a property called “__DisplayShowHideRibbonActionId” that is not in a webs propertybag by default and when set to false the ribbon is shown to all users.

Simple code snippet of how this could be implemented(demo code, should not be used in production):


public static string CreateWeb(SPWeb parentWeb, string title, string webTemplate)
{
    parentWeb.AllowUnsafeUpdates = true;
    using (SPWeb newWeb = parentWeb.Webs.Add(title, title, string.Empty, parentWeb.Language, 
                                                              webTemplate, false, false))
    {
        // Show Ribbon by default
        newWeb.AllProperties["__DisplayShowHideRibbonActionId"] = false.ToString();
        newWeb.Update();
        return newWeb.Url;
    }
}

It feels a bit hackish to do it this way, so if anyone knows of a better way to make the ribbon visible when a web is created then please to tell :)