In SharePoint Portal Server 2003 we had allowed users to add web parts from the online web part gallery. In going to MOSS 2007 we decided that we no longer wanted users to be able to do this as it tended to reduce the security of the site and adversely affect performance (not to mention that fact that it was annoying having a weather web part on every page). As part of my upgrade script I wanted to be able to disable the online web part gallery. You can do this easily via the central admin tool from here: Central Administration > Application Management > Security for Web Part Pages. The code to do this is extremely easy – just get an SPWebApplication object, set the AllowAccessToWebPartCatalog property and call Update():

1string url = Params["url"].Value.TrimEnd('/');
2SPWebApplication wa = SPWebApplication.Lookup(new Uri(url));
3wa.AllowAccessToWebPartCatalog = allowAccessToWebPartCatalog;
4wa.Update();

The syntax of the command, gl-setallowaccesstoonlinegallery, can be seen below.

C:\>stsadm -help gl-setallowaccesstoonlinegallery

stsadm -o gl-setallowaccesstoonlinegallery

Sets whether or not to allow access to the online web part gallery.

Parameters:
        -url <web application>
        [-allowaccesstowebpartcatalog <true (default) | false>]

Here’s an example of how to disable access to the online web part gallery:

stsadm –o gl-setallowaccesstoonlinegallery –url "http://intranet/" –allowaccesstowebpartcatalog false