How to deactivate the delegate control feature after its first load?
-
03-10-2020 - |
Pergunta
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;
}
});
}
}
Solução
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).
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange