views:

215

answers:

2

We have a custom master page that is deployed to the MySite web application per these instructions - http://www.sharepointblog.com/2008/07/sp2007-custom-master-pages-on-subsites.html

However, we require the ability to deactivate the feature on all the site collections that are within the MySite webapplication. The feature is built as a site collection scope. How would we deactivate them on an application that has potentially 3000+ MySites?

+4  A: 

I would build a simple console application which iterates over all site collections (MySites) of your web application and deactivates the feature. You'll have to run this piece of code with elevate privileges (SPSecurity.RunWithElevatedPrivileges) so you have the permission to deactivate a site collection feature.

private static void DeleteWebsiteCollections()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://MySiteHostWebApp"));
                SPSiteCollection mySites = webApp.Sites;

                foreach (SPSite site in mySites)
                {
                    site.Features.Remove(new Guid("place your feature id here"));

                    if (null != site)
                    {
                        site.Dispose();
                    }
                }
            });
        }
Flo
This is pretty much exactly how we did it, only I wrapped it in a feature which was deployed to the My Site web application. When the feature deactivated, we used the above code to remove the feature. Thanks Flo!
esp
A: 

This code can be stapled into the masterpage too. Only site.Features.Remove(new Guid("place your feature id here")); should remain.

Mauricio