views:

97

answers:

2

Hey guys.

I've developed a web part using the wspbuilder tool (Web part with feature).

When deployed (to a site collection), you have to activate the feature in order to use this web part - so far so good.

However, when deactivating the feature, the web part remains on any site where it's been added, and furthermore, it's still available in the web part gallery?

Is this expected behaviour? Is there no way of removing the web part from all subsites in the site collection, and also remove it from the web part gallery?

Thanks ;)

+1  A: 

This is expected behavior. You could remove it automatically, but you would have to write a feature receiver to accomplish that.

More info about creating a feature receiver for SharePoint 2007: http://sharepointdevwiki.com/display/public/How+to+add+a+Feature+Receiver+to+a+Feature

Tom Vervoort
I know a little about feature receivers as well, and I've tried fiddling around with this as well. However, I seem completely unable to remove the web part from the sites using it. I haven't attacked the web part gallery yet, because I wanted to remove it from the sub sites first
Dynde
You may have to use a WebPartManager to remove instances of your webpart from sites before you can remove it from the webpart gallery.
Shaneo
It's perfectly safe to remove webparts from the Web Part Gallery while they are still being used on pages. What will happen is that the existing instances will continu to work, but users are unable to create new instances. You can do the same thing through the user interface. As Shaneo states, you'll have to check each page from each site and remove the webpart using the WebPartManager or LimitedWebPartManager. It doesn't matter if you do this before or after you have removed the webpart from the Web Part Gallery.
Tom Vervoort
Okay... So I definitely SHOULD be able to remove the web part using the LimitedWebPartManager? Because that's what I'm trying to do.I have a loop of all webparts in a SPWeb.SPLimitedWebPartManager.WebParts. In this loop, I print all webparts titles, and (attempts to) remove my specific webpart using SPLWPM().DeleteWebPart(myWebPart); but absolutely nothing happens :/
Dynde
You should. Don't forget to call SPLWPM.Web.Update() after deleting the webparts. Also, be sure to put your LimitedWebPartManager in a using block (it implements IDisposable) and call SPLWPM.Web.Dispose() just before exiting the block. This prevents a memory leak caused by a bug in the object model.
Tom Vervoort
A: 

WSPBuilder automatically adds the removal event receiver to the feature when you create a web part. Very convenient.

Vladi Gubler