I have created an web event receiver but the webprovisioned event handler fires twice. I have set the scope to web, but it still fires twice.
Problem 1
This is elements file:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers Scope="Web">
<Receiver>
<Name>WebEventReceiverWebProvisioned</Name>
<Type>WebProvisioned</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>WebEventReceiver</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
Event:
public override void WebProvisioned(SPWebEventProperties properties)
{
SPWeb web = (SPWeb)properties.Web
web.Navigation.UseShared = true;
web.Update();
}
I saw another post which mentioned that if the scope is set to web it will fire only once, but it my case it is still firing.
Update 1
I tried the following code. It sets the options correctly, but they are not applied to the UI yet. I have to click OK once again to see the changes.
Just to be sure that you guys get what I am trying to achieve. I am trying to set the top navigation, not the left navigation.
// PublishingWeb Navigation
var pubWeb = PublishingWeb.GetPublishingWeb(web);
var webNavigationSettings = new WebNavigationSettings(web);
webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;
pubWeb.Navigation.CurrentIncludeSubSites = true;
pubWeb.Navigation.CurrentIncludePages = true;
pubWeb.Navigation.CurrentDynamicChildLimit = 20;
pubWeb.IncludeInGlobalNavigation = true;
pubWeb.Navigation.InheritGlobal = true;
pubWeb.Navigation.GlobalIncludeSubSites = true;
pubWeb.Navigation.GlobalIncludePages = true;
webNavigationSettings.AddNewPagesToNavigation = false;
webNavigationSettings.CreateFriendlyUrlsForNewPages = false;
webNavigationSettings.Update();
pubWeb.Update();
web.Update();
Problem 2
When I create a new site the top navigation does not get applied to this newly created site.Any ideas?