Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am developing a sharepoint feature which takes a backup of the site at sitecollection level and at site level whenever a user tries to delete the site. The feature is working fine without issues for the existing sitecollection and sites when the feature is activated. To give more picture, i am taking backup through code in events SiteDeleting and WebDeleting events. This events are hooked up using FeatureActivated event. I understand this ensures the event are hooked only up for the existing sites because of my code(i am hooking SiteDeleting and WebDeleting events in FeatureActivated event). After the feature activated, if i create a new site collection/sites the feature is not working(i.e backup is not taken when deleting the site).

I was trying to activate the event for new sites and hence i looked if there will be similar events like sitecreating where i can again hook up the SiteDeleting and WebDeleting events for new sites. But i came to know after some reasearch that there is no sitecreating event which can be used. After bit of googling i found that it can be done through a feature called stapling where we need to create another feature that attaches this feature to the new sites through template name. I have tried installing both the feature(my original and stapling feature) but it never seems to be working...

I am very new to SharePoint development and its taking time for fixing it. It will great if someone can help me to make the feature to work for the new sites as well.. I believe i am doing something wrong in scope parameter of feature.xml..listed below the feature.xml contents.

SiteDeletFeature (My original Feature) *Feature.xml* <

?xml version="1.0" encoding="utf-8" ?>
<Feature Title="My SharePoint Delete Feature"
         Scope ="WebApplication" 
         ActivateOnDefault="True" 
         Hidden="false"
         Id="DA910034-F270-4932-90D0-05AE2EE13192"
         xmlns="http://schemas.microsoft.com/sharepoint/"
         ReceiverAssembly="My.Sharepoint.SiteDeleteFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=762e98b8afce5f9b"
         ReceiverClass="My.Sharepoint.SiteDeleteFeature.DeleteFeatureCallOut">
  <ElementManifests>
    <ElementManifest Location="Elements.xml"/>
  </ElementManifests>
</Feature>

SiteDeleteFeatureStapling *Feature.xml*

<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
    Id="D0495B32-9F78-4142-A456-48B3ECBFFD6C" 
    ActivateOnDefault="True"
    Title="My SharePoint Delete Feature"
    Description="My SharePoint Delete Feature"
    Version="0.0.0.0"
    Scope="Farm">
    <ElementManifests>
        <ElementManifest Location="FeatureStapling\FeatureStapling.xml" />
    </ElementManifests>
</Feature>

FeatureStapling.xml

<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <FeatureSiteTemplateAssociation Id="DA910034-F270-4932-90D0-05AE2EE13192" TemplateName="STS#0" />
    .
    .
    .//goes on, i have included all template names
    <FeatureSiteTemplateAssociation Id="DA910034-F270-4932-90D0-05AE2EE13192" TemplateName="MyCOMMUNITY" />
</Elements>

I have tried various option in Scope parameter for SiteDeleteFeatureStapling like Web,Site but nothing worked out...

Could someone help me to fix this issue?

share|improve this question
add comment

1 Answer 1

Try changing your templatename to GLOBAL, that will take care of all of the site definitions except for the blank site, which you can include as STS#1. The stapling also doesn't work for templates. See my question here on an idea on how to get around this in SP2010: http://www.sharepointoverflow.com/questions/3975/sp-2010-templates-and-feature-stapling

share|improve this answer
    
Do you mean in featurestapling.xml, i should include only one line like this ? <FeatureSiteTemplateAssociation Id="DA910034-F270-4932-90D0-05AE2EE13192" TemplateName="GLOBAL" /> Sorry, i am very new to SP...doing this will be sufficient? I understand everything else i am doing is correct.. –  Anonymous Jul 16 '10 at 4:51
1  
yea, you'll need two lines, the GLOBAL and STS#1 to staple ALL site definitions. –  Steve Lineberry Jul 16 '10 at 13:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.