views:

32

answers:

1

Hi All,

I am developing a sharepoint feature which takes a backup of the site at sitecollection level and at site level whenevar 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/"&gt;
 <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 some one help me to fix this issue...Thanks in advance!

Regards Bala

A: 

hi Bala

FeatureStapling.xml must have scope = "Farm"

SiteDeletFeature must have scope = "Web"

Per Jakobsen
I need to activate the feature from central admin and not at sitecollection level..the above setting is not listing the feature in central admin features "Manage Web Application Features"
Bala
If you want Feature stapling to work it needs to be at Web scope. If you also want to manually activate at web application scope, then you need two features :-(, the one at web scope can be hidden. BTW TemplateName="GLOBAL#0" will handle most site definitions (Not blank site)
Per Jakobsen
Thanks for the reply Per!..Do you mean 2 more (so totally 4?) What will be the scope of the 2 new feature then ? and what the feature.xml should contain for the new 2 features ?
Bala
Just one more that you already have. If you make SiteDeletWebFeature similar to SiteDeletFeature except Id=new guid, Scope=Web and Hidden=True and make SiteDeleteFeatureStapling point to SiteDeletWebFeature you should be good to go
Per Jakobsen