In order to set the welcome page of a web template, the documented and most common way is to use the publishing feature in your onet.xml, which have a feature parameter for setting the welcome page. Sometimes you don’t want to use the publishing framework for various reasons. In my case I was creating a variant of the team site STS#0 web template, and in my opinion the publishing feature does not belong in a team site – especially if it’s just there for setting the welcome page.
It’s pretty easy to set the welcome page programmatically in a feature receiver, but in these no-server-side-code/cloud-compatible times we do our best to avoid that stuff, don’t we?
Surprisingly Google does not give any results on how to set the welcome page url declaratively (without resorting to the publishing feature), only programmatically. The solution is actually very simple, and was discovered by setting a custom welcome page in a web, exporting the web as template and investigating the modules inside the exported .wsp. The welcome page url property is persisted using the rootfolder’s property bag.
To set a custom welcome page in a web template using no-code and no-publishing, do the following
- Create a web-scoped feature, e.g. WebTemplatePropertyBagFeature
- Add an empty element, e.g. WelcomePageProperty, to the project and to the feature above. The Elements.xml for the WelcomePageProperty element should look similar to the following (replace SitePages/MyCustomFrontPage.aspx with the name of the page you want to use as frontpage for the web)
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <PropertyBag Url="" ParentType="Folder" RootWebOnly="FALSE"> <Property Name="vti_welcomepage" Value="SitePages/MyCustomFrontPage.aspx" Type="string" /> </PropertyBag> </Elements>
- Find the WebTemplatePropertyBagFeature’s feature guid, and add it to the web template’s onet.xml WebFeatures.
- Deploy the solution and create a new site based on the webtemplate. The frontpage should now be your custom page.