I have a module for Stapling features in SPSPERS#2
(My Sites).
In the Elements.xml
of the stapling module I have this:
<!-- My Site contents (Content Types, lists, etc)-->
<FeatureSiteTemplateAssociation Id="fc57dad0-c4d0-4827-9ade-eff87b9e6d3b" TemplateName="SPSPERS#2" />
<!--my site pages (feature with an event receiver that adds XsltListViewWebPart instances
to my custom pages-->
<FeatureSiteTemplateAssociation Id="fe02ff99-6b1f-4471-a6cf-a240d3e5fcf5" TemplateName="SPSPERS#2" />
<!--branding y custom masterpage-->
<FeatureSiteTemplateAssociation Id="9a17f4a2-3025-4b14-ae54-d489fe0f2449" TemplateName="SPSPERS#2" />
The problem is that both Custom Lists and Custom Pages are created in the stapling but when I visit one of my custom pages nothing is there. Content only appears if I deactivate the feature (fe02ff99-6b1f-4471-a6cf-a240d3e5fcf5
) and then activate throughout the UI.
This is the code of the feature fe02ff99-6b1f-4471-a6cf-a240d3e5fcf5
event receiver:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
if (properties != null)
{
SPWeb mySiteWeb = properties.Feature.Parent as SPWeb;
if (mySiteWeb != null)
{
try
{
mySiteWeb.AllowUnsafeUpdates = true;
//Aprovisionamiento de Biblitoeca de Documentos
ProvisionWebPart(mySiteWeb, "mydocuments.aspx", "Documents", "All", "All Documents");
//Aprovisionamiento de Calendario
ProvisionWebPart(mySiteWeb, "myevents.aspx", "Calendar", "Calendar", "Events");
//Aprovisionamiento de Favoritos
ProvisionWebPart(mySiteWeb, "myfavourites.aspx", "FavouritesList", "All Items", "My Favourites");
}
catch (Exception ex)
{
}
finally
{
mySiteWeb.AllowUnsafeUpdates = false;
}
}
}
}
And the code of ProvisionWebPart Method
private static void ProvisionWebPart(SPWeb mySiteWeb, string page, string listName, string viewName, string title)
{
using (SPLimitedWebPartManager webpartmanager = mySiteWeb.GetLimitedWebPartManager(page, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
SPList lista = mySiteWeb.Lists[listName];
XsltListViewWebPart newLvwp = new XsltListViewWebPart();
newLvwp.ListName = lista.ID.ToString("B").ToUpper();
newLvwp.ViewGuid = lista.Views[viewName].ID.ToString("B").ToUpper();
newLvwp.Title = title;
//listviewwebpart.AllowClose = false;
webpartmanager.AddWebPart(newLvwp, "MiddleZone", 1);
mySiteWeb.Update();
newLvwp.Dispose();
}
}
Any idea why is not showing content on stapling but on deactivating and activating manually?