In my last post "SharePoint 2010 Deploy Master Page using Visual Studio Solution Project and Set it as Default Master Page.", i explained how to add a master page and set it as a default. I suggest to read the last blog first.
What causes the issue?
Answer: When a file is deployed to the server using a Visual Studio Solution, the file gets deleted first and than added back to server. But when we assign a file as a Default Master Page it "CANNOT" be deleted. So just follow the below given steps to make it a fix.Solution
Just write a deactivating event in the feature receiver setting V4.master as a master page. Please checkout the code below./// <summary> /// Set the v4.master as default master for site. /// </summary> /// <param name="properties"></param> public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSecurity.RunWithElevatedPrivileges(delegate { using (SPWeb _web = ((SPSite)properties.Feature.Parent).RootWeb) { Uri _siteMaster = new Uri(string.Format("{0}/_catalogs/masterpage/v4.master", _web.Url)); _web.MasterUrl = _siteMaster.AbsolutePath; _web.CustomMasterUrl = _siteMaster.AbsolutePath; _web.Update(); } }); }Hope this was helpful to you. Thanks for reading the blog.
Error occurred in deployment step 'Activate Features': Unable to cast object of type 'Microsoft.SharePoint.SPWeb' to type 'Microsoft.SharePoint.SPSite'.
ReplyDeleteI m geeting this error what i do .Please tell me ASAP>
Its because the feature you are using is a Web Based feature.
DeleteIn the above given code use this "SPWeb _web = ((SPWeb)properties.Feature.Parent).Site.RootWeb;"
Everyone will also receive an error that the new master does not exist. this is because it has not been set as the default in Designer. Doing it as a feature in Visual Studio does not work.
ReplyDeleteThanks, it works fine with SharePoint 2013
ReplyDelete