Monday, October 24, 2016

WebProvisioned event receiver

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers >
    <Receiver>
      <Name>EventReceiver1WebProvisioned</Name>
      <Type>WebProvisioned</Type>
      <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
      <Class>Stefan.SharePoint.EventReceiver1.EventReceiver1</Class>
      <SequenceNumber>10000</SequenceNumber>
    </Receiver>
  </Receivers>
</Elements>

Scope:

<Receivers Scope="Site">

custom WebProvisioned receiver provides:
<Properties>
  <Property Key="ReceiverScope" Value="Site" />
  <Property Key="Web.MasterUrl" Value="~SiteCollection/_catalogs/masterpage/v4.master" />
  <Property Key="Web.AlternateCssUrl" Value="/_layouts/styles/mydefault.css" />
  <Property Key="CustomProperty.Test" Value="Some value" />
  <Property Key="PublishingWeb.IncludeInCurrentNavigation" Value="true" />
  <Property Key="Navigation.GlobalIncludePages" Value="true" />
  <Property Key="Navigation.GlobalIncludeSubSites" Value="true" />
</Properties>


Property Key="Web.MasterUrl" Value="${~Parent}" />
  <Property Key="Web.CustomMasterUrl" Value="${~ParentNoRoot}" />
  <Property Key="Navigation.GlobalIncludePages" Value="${~SiteCollection}" />
As you see, you can specify special tokens in the “Value” attribute of the feature property elements too, these three options are available:
  • ${~Parent} – with this token you specify that the property of the “Key” attribute will be copied from the parent web of the current web
  • ${~ParentNoRoot} – this is almost the same as the first option, the only difference being that if the parent site is the root site of the current site collection the property won’t be copied to the current web (meaning that if the current web is not a child of the root web, the property will get copied).
  • ${~SiteCollection} – this token specifies that the property will be copied from the root web of the current site collection (no matter whether it is the parent of the current web or not)
In the case of the ${~ParentNoRoot} token you saw that there will be cases when the specified web property won’t get copied to the current web (for first level children). In this case you will need to specify two feature property elements with the same “Key”:
  <Property Key="Web0.CustomMasterUrl" Value="~SiteCollection/_catalogs/masterpage/v4.master" />
  <Property Key="Web1.CustomMasterUrl" Value="${~ParentNoRoot}" />






SPWeb’s MasterUrl, CustomMasterUrl and AlternateCssUrl properties for publishing sites). This sample would do the trick:
  <Property Key="Web.MasterUrl" Value="~SiteCollection/_catalogs/masterpage/v4.master" />
  <Property Key="Web.CustomMasterUrl" Value="~SiteCollection/_catalogs/masterpage/v4.master" />
  <Property Key="Web.AlternateCssUrl" Value="" />
  <Property Key="CustomProperty.__InheritsMasterUrl" Value="false" />
  <Property Key="CustomProperty.__InheritsCustomMasterUrl" Value="false" />
  <Property Key="CustomProperty.__InheritsAlternateCssUrl" Value="false" />

No comments:

Post a Comment