Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:17:14+00:00 2026-05-28T15:17:14+00:00

I am developping a web part that I can’t update on the SharePoint server

  • 0

I am developping a web part that I can’t update on the SharePoint server without deleting it in webpart gallery. Then, I run in power shell :

  • Update-SPSolution …
  • Disable-SPFeature …
  • Enable-SPFeature …

I tried to delete the web part in the gallery programmatically in the event receiver, but it causes SharePoint to fail :

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            using (SPWeb web = site.RootWeb)
            {
                SPList list = web.Lists["Web Part Gallery"];

                // go through the items in reverse
                for (int i = list.ItemCount - 1; i >= 0; i--)
                {
                    // format name to look like a feature name
                    string webpartName = list.Items[i].Name;

                    webpartName = webpartName.Substring(0, webpartName.IndexOf('.'));

                    // delete web parts that have been added
                    if (properties.Feature.Definition.DisplayName == webpartName)
                    {
                        list.Items[i].Delete();

                        break;
                    }
                }
            }
        }

Any idea what am i doing wrong ? thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:17:15+00:00Added an answer on May 28, 2026 at 3:17 pm

    I am coming back to share the solution.
    Here is the correct code to delele the web part from the gallery when deactivating the feature :

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            try
            {
                int ItemID = -1;
                using (SPSite oSite = (SPSite)(properties.Feature.Parent))
                {
                    using (SPWeb oWeb = oSite.RootWeb)
                    {
                        SPList oList = oWeb.Lists["Galerie de composants WebPart"];
    
                        if (oList == null)
                        {
                            // si SharePoint en anglais 
                            oList = oWeb.Lists["Web Part Gallery"];
                        }
                        // si oList == null, alors aucun de traitement
                        // on ne connais pas le nom de la liste 
                        // de la gallerie de web part
                        if (oList != null)
                        {
                            for (int i = 0; i < oList.ItemCount; i++)
                            {
                                if (oList.Items[i].Title.Equals(WebPartTitle))
                                {
                                    ItemID = oList.Items[i].ID;
                                    break;
                                }
                            }
                            if (ItemID != -1)
                            {
                                SPListItem oItem = oList.GetItemById(ItemID);
                                oItem.Delete();
                                oList.Update();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //will throw to and error page
                throw new Exception(String.Format("The has been an error "
                + "removing the WebPart from the Gallery; {0}", e.ToString()));
            }
        }
    

    Finally, after adding this code in the event receiver, the procedure for updating the Web Part solution is :

    • Disable-SPFeature …

    • Uninstall-SPFeature …

    • Update-SPSolution …

    • Install-SPFeature …

    • Enable-SPFeature …

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing web app that user can save his/her work to server. The data
We currently have a product that uses Sharepoint and a number different Web Part
We are developing several web applications to run on our own server that will
When developing web parts in SharePoint can I inherit from the existing web parts
I'm developing a web site that has a search box as part of the
I'm developing a SharePoint 2010 Web Part (in C#) which needs to pull user
I have a web-based documentation searching/viewing system that I'm developing for a client. Part
I am developing a Silverlight web part for Sharepoint 2010. I have a button
I'm developing a JavaScript application that's meant to be run either from a web
When developing with Django without a web server (serving directly from Django) I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.