Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Populate Webpart into the gallery

  Asked By: Eve    Date: Dec 01    Category: Sharepoint    Views: 2872

I have a requirement to delete the webpart from the gallery on deactivating an feature(it is feature for customizing list event handler).
I do it using the following code,

using (SPWeb web = properties.Feature.Parent as SPWeb)
SPList list = web.Lists["Web Part Gallery"];
for (int i = list.ItemCount - 1; i >= 0; i--)
if (list.Items.DisplayName.Equals("RegisterEventHandler"))


Can anyone please suggest how to populate the webpart on activating the feature using



3 Answers Found

Answer #1    Answered By: Jaya Deoghar     Answered On: Dec 01

your requirment is not clear to me . what do u exactly want ? please explain a bit

Answer #2    Answered By: Candi Branch     Answered On: Dec 01

So I assume your requirements as follows:
1. Create a feature  for deploying a web  part.
2. On Feature activation populate  the web part  gallery.
3. On Feature deactivation remove the web part from the web part gallery.

If all this sounds good & correct then you should take a look at following blog for all the details:

Basically your elements file should have the module entry for e.g. as below for the web part to be auto populated in gallery  on feature activation:

Answer #3    Answered By: Jan Chen     Answered On: Dec 01

Basically I have an event  handler class (inheriting SPItemEventReceiver) and a feature  class(inheriting SPFeatureEventReceiver) as a feature in my project. I have also added an webpart  in the same project. This webpart will be used to register my event handler  to any particular list  ie., in the webpart the user enters the name of the list which needs to be registered to the EventHandler and click a button which does the job.

On deploying the feature (.wsp) using  the STSADM command the feature and the web  part gets deployed sucessfully. On deployment the webpart gets populated automatically in the web part  gallery.

On deactivating the feature the webpart gets removed(deleted) from the gallery. I have written the code  for removing the webpart from the gallery  in the FeatureDeactivated event.

Now on activating  the feature i want the webpart to be populated into the gallery. can you please suggest me how to do it programmatically onthe FeatureActivated event ?????

Didn't find what you were looking for? Find more on Populate Webpart into the gallery Or get search suggestion and latest updates.