Following example shows how to change the master page of SharePoint site on feature activation:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb currWeb = properties.Feature.Parent as SPWeb;
            try
            {
                currWeb.AllowUnsafeUpdates = true;
                SPWeb rootWeb = currWeb.Site.RootWeb;
                if (rootWeb.GetFile(rootWeb.Url + "/_catalogs/masterpage/NewMaster.master").Exists)
                {
                    Uri masterUri = new Uri(rootWeb.Url + "/_catalogs/masterpage/ NewMaster .master");
                    currWeb.MasterUrl = masterUri.AbsolutePath;
                    // Sets application master page
                    currWeb.CustomMasterUrl = masterUri.AbsolutePath;
                    currWeb.Update();
                }
                currWeb.AllowUnsafeUpdates = false;
            }
            catch (Exception ex)
            {
                // Log exception
            }
        }


0 comments

My SharePoint CodePlex Projects

SharePoint 2010 Autocomplete Lookup Field

Export Version History Of SharePoint 2010 List Items to Microsoft Excel.