Set a Custom Master Page during Feature Activation


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPSite currentSite = (SPSite)properties.Feature.Parent;           
    SPWeb currentWeb = currentSite.RootWeb;
    Uri masterURI = new Uri(currentWeb.Url + "/_catalogs/masterpage/Customv4.master");
    Uri customMasterURI = new Uri(currentWeb.Url + "/_catalogs/masterpage/Customv5.master");
    currentWeb.MasterUrl = masterURI.AbsolutePath; //Non publishing pages
    currentWeb.CustomMasterUrl = customMasterURI.AbsolutePath;   //Publishing pages
    currentWeb.Update();
}

Set a Custom Master Page during Feature Deactivation


public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    SPSite currentSite = (SPSite)properties.Feature.Parent;
    SPWeb currentWeb = currentSite.RootWeb;
    Uri masterURI = new Uri(currentWeb.Url + "/_catalogs/masterpage/Customv4.master");
    Uri customMasterURI = new Uri(currentWeb.Url + "/_catalogs/masterpage/Customv5.master");
    currentWeb.MasterUrl = masterURI.AbsolutePath; //Non publishing pages
    currentWeb.CustomMasterUrl = customMasterURI.AbsolutePath; //Publishing pages
    currentWeb.Update();
}

Other languages

This article is also available in the following languages: