Deploying Custom Master Page in SharePoint
Using Visual Studio I am deploying the master page am creating an Empty Project, in that Feature I am adding a new Feature Scope I am selecting as” Site “and adding the Event Receiver.
I am adding the module it is used to deploy files to the SharePoint Environment,
In That Module I am having sample.txt I am changing it to CustomMaster.master
Finally my solution is looks as shown below.
In Feature1.EventReceiver.cs I am adding the Below code
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite siteCollection = (SPSite)properties.Feature.Parent;
SPWeb web = siteCollection.RootWeb;
Uri masteruri = new Uri(web.Url+"/_catalogs/masterpage/CustomMaster.master");
web.MasterUrl = masteruri.AbsolutePath;
web.CustomMasterUrl = masteruri.AbsolutePath;
web.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite siteCollection = (SPSite)properties.Feature.Parent;
SPWeb web = siteCollection.RootWeb;
Uri masteruri = new Uri(web.Url + "/_catalogs/masterpage/Seattle.master");
web.MasterUrl = masteruri.AbsolutePath;
web.CustomMasterUrl = masteruri.AbsolutePath;
web.Update();
}
Module1 in Element.xml I am adding the below lines
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Module1" List="116" Url="_catalogs/masterpage">
<File Path="Module1\CustomMaster.master" Url="CustomMaster.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />
</Module>
</Elements>
Once completed all the steps deploy the solution in visual studio
It will be changed as our custom master as shown below.
No comments:
Post a Comment