Question

I have created a delegate control and it works fine. Inside this delegate control I add a webpart to the welcome page. Thats it!

After this action I would like to deactivate the delegate control feature. How to do that?

This is my current code:

public partial class SiteLidMaatschapProvisioning : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AddSiteLidMaatschapWebPart();
            // Some logic to deactivate the delegate control feature ??
        }

        /// <summary>
        /// Adds the site lid maatschap web part.
        /// </summary>
        public void AddSiteLidMaatschapWebPart()
        {
            SPSecurity.RunWithElevatedPrivileges(
            delegate()
            {
                using (SPWeb web = SPContext.Current.Web)
                {
                    web.AllowUnsafeUpdates = true;
                    var welcomePageUrl = web.RootFolder.WelcomePage;
                    SPFile page = web.GetFile(welcomePageUrl);

                    if (page.CheckOutType == SPFile.SPCheckOutType.None)
                    {
                        page.CheckOut();
                    }

                    using (SPLimitedWebPartManager spLWM = web.GetLimitedWebPartManager(welcomePageUrl, PersonalizationScope.Shared))
                    {
                        var siteLidmaatschapWebpart = new SiteLidmaatschapWebpart();
                        if (!spLWM.WebParts.Contains(siteLidmaatschapWebpart))
                        {
                            spLWM.AddWebPart(siteLidmaatschapWebpart, "LeftZone", 10);
                            spLWM.SaveChanges(siteLidmaatschapWebpart);
                        }

                    }

                    page.CheckIn("Add webpart to welcome page");
                    web.AllowUnsafeUpdates = false;
                }
            });
        }
    }
Was it helpful?

Solution

You can deactivate a feature with the following code:

web.Site.Features.Remove(new Guid("GUID_OF_YOUR_FEATURE"), true);

Add the code after adding the web part (line 38 in your code).

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top