mercredi 3 décembre 2014

Feature Stapler not working



I have created some branding for the SharePoint 2013 MySites with a feature stapler so that it can also add the branding to the Blog, Apps and Tasks but it's not working. The branding applies to the Newsfeed and the Mysites homepage but doesn't apply to the Blog, Apps or Tasks.


Here is my code.


Feature Activation.cs



using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace My_Sites_Branding.Features.ActivateMySiteBranding
{
/// <summary>
/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
/// </summary>
/// <remarks>
/// The GUID attached to this class may be used during packaging and should not be modified.
/// </remarks>


[Guid("e60d019f-bcbb-43a3-8996-83f46cbbd7aa")]
public class ActivateMySiteBrandingEventReceiver : SPFeatureReceiver
{
// Uncomment the method below to handle the event raised after a feature has been activated.


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite siteCollection = (SPSite)properties.Feature.Parent;
string masterUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl, "_catalogs/masterpage/CustomProfile.Master");

foreach (SPWeb web in siteCollection.AllWebs)
{
try
{
web.MasterUrl = masterUrl;
web.CustomMasterUrl = masterUrl;
web.Update();
}
catch
{
if (web != null)
web.Dispose();
throw;
}
if (web != null)
web.Dispose();
}
}

// Uncomment the method below to handle the event raised before a feature is deactivated.
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite siteCollection = (SPSite)properties.Feature.Parent;
string masterUrl = SPUrlUtility.CombineUrl(siteCollection.ServerRelativeUrl, "_catalogs/masterpage/mysite15.master");
foreach (SPWeb web in siteCollection.AllWebs)
{
try
{
web.MasterUrl = masterUrl;
web.CustomMasterUrl = masterUrl;
web.Update();
}
catch
{
if (web != null)
web.Dispose();
throw;
}
if (web != null)
web.Dispose();
}
}
}

}


Elements file of my Stapler Module



<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://ift.tt/sQmbje">
<FeatureSiteTemplateAssociation Id="e60d019f-bcbb-43a3-8996-83f46cbbd7aa" TemplateName="SPSPERS#2" />
</Elements>


Where am I going wrong?








0 commentaires:

Enregistrer un commentaire