SharePoint Web Parts aren’t Populated in Gallery

I’ve no idea what the deal was, but a client’s SharePoint site lost all of the Content Editor Web Parts in their My Sites.

The thing about My Sites is that each individual one is a site collection–so it’s not as though populating the gallery in the parent site will help restore the web parts.

Thanks to these two articles, I wrote a quick program to re-populate the gallery:…

The code was pretty simple with that help:

SPWebApplication webApp = SPWebApplication.Lookup(new Uri(sSite));

FileInfo f = new FileInfo(sDWPFileLocation);
FileStream s = f.Open(FileMode.Open, FileAccess.Read);
//Execute any logic you need to against the web application
//Iterate through each site collection
foreach (SPSite siteCollection in webApp.Sites)
foreach (SPWeb _web in siteCollection.AllWebs)
using (_web)

_web.AllowUnsafeUpdates = true;
siteCollection.AllowUnsafeUpdates = true;
SPList _list = _web.Lists[“Web Part Gallery”];
SPFolder _root = _list.RootFolder;
SPFile _spFile = _root.Files.Add(sFileName, s);
catch (Exception ex)




Leave a Reply

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

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

Facebook photo

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

Connecting to %s