Domanda

I have a feature that deploys a site in a folder in the root of the parent site. When we want to uninstall this feature, the only way to remove the files it deploys is by programmaticaly remove them using the SPFolder.Delete() method. I want to do this using an Event Receiver which I developed. The problem is that when I try to uninstall the feature, the event receiver doesn't catch the Event and nothing happens. This is the class and method where I do this:

public class Feature1EventReceiver : SPFeatureReceiver
{    
  public override void FeatureDeactivating(SPFeatureReceiverProperties properties){
    //delete folders
  }
}

I'm suspecting the reason the event receiver doesn't catch the event is because the event receiver is in a different project than the feature, so my question is which of these file structures should I use?

Solution
|
+   Webpart (project)
    |
    +   Features (folder)
        |
        +   Web part (feature)
        +   EventReceiver (feature)

OR

Solution
|
+   Webpart (project)
    |
    +   Features (folder)
        |
        +   Web part (feature)
+   EventReceiver (project)
    |
    +   Features (folder)
        |
        +   EventReceiver (feature)

Let me know if you think the reason to fail in catching the event migt be other.

EDIT I have previously tried @Evariste layout but I always get a "this sandboxed solution has exceeded its daily resource usage quota" error when I try to deploy although the Solution Gallery looks like this: enter image description here This is how my project structure looks when I get that error: enter image description here

È stato utile?

Soluzione

IMO, the only correct handling of this problem would be to have only one VS project, building into one single WSP package. And also: one feature only. The feature that provisions files should be the one that deletes them at deactivation. It does not make sense to activate F01 and deactivate F02 to undo what F01 did! Furthermore, how F02 would be activated in the first place!?

You then should have:

Solution
|
+   Webpart (project)
    |
    +   Features (folder)
        |
        +   Web part (feature) with EventReceiver

That's all. From Visual Studio, once the feature is created simply right-click on it and choose to add a Feature Event Receiver. The added feature class has an Id attribute, that's automatically wired-up with the parent feature (see it in the feature's properties Window) when the WSP is built.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top