Deploy masterpage to subsite using module
-
10-12-2019 - |
Question
I created a search-center and want to apply a custom masterpage to it. I want to deploy the masterpage using a module and the feature of my solution. I created a module and the Elements.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="SearchcenterModule" Url="Suche/_catalogs/masterpage">
<File Path="SearchcenterModule\minimal.master" Url="minimal.master" />
</Module>
</Elements>
On activating my feature in the site-collection-features I get an error
(null) "Suche" not found.
...
where "Suche" is the Name of my subsite, i.e. : http://mysharepoint/Suche
Of course I can add the file manually but there must be a way to deploy it using the feature-activation.
Thank you for your help.
Solution
I don't know the solution but, have you tried to set feature scope to web, use default module definition and activation of this module on the Suche subsite?
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MasterPageModule" Url="_catalogs/masterpage">
<File Url="MasterPage.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="False" />
</Module>
</Elements>
If it doesn't work, have you tried to use ~Site token?
<Module Name="SearchcenterModule" Url="~Site/_catalogs/masterpage">
OTHER TIPS
Masterpages and pagelayout can only be deployed to SiteCollections, not sites/subsites.
So your feature needs to be Site scoped. You can always in your FeatureReceiver set the masterpage on a specific SPWeb
.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="SearchcenterModule" Url="_catalogs/masterpage">
<File Url="minimal.master" IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" />
</Module>
</Elements>
IgnoreIfAlreadyExists
makes sure you overwrite it when you deploy so new changes appear. Type="GhostableInLibrary"
makes sure the new masterpage/pagelayout is visible in the Masterpage & Pagelayouts gallery.