Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damien Holley 179 posts 540 karma points
    Apr 29, 2017 @ 11:03
    Damien Holley
    0

    Remove a section package correctly

    Hi everyone, I am nearly finished with the code for my section, one issue cropped up though, if you remove the package it does not remove the section from the applications.config file. Is there a command or c# override/function I can put into the package.xml file that will tell it to actually remove it on uninstall?

  • Marcio Goularte 374 posts 1346 karma points
    Apr 30, 2017 @ 02:00
    Marcio Goularte
    0

    You need create a class that inherits IPackageAction. I made a simple sample code that might help.

    References http://endzonesoftware.com/umbraco-install-package-action-adds-new-tab-dashboard-not-section-2/

    https://24days.in/umbraco-cms/2013/v7-packages/

    using System.Xml;
    using umbraco.interfaces;
    using Umbraco.Core;
    using Umbraco.Core.IO;
    
    namespace OurUmbraco
    {
        public class RemoveAppAction : IPackageAction
        {
            public string Alias()
            {
                return "YourSection";
            }
    
            public bool Execute(string packageName, XmlNode xmlData)
            {
                return true;
            }
    
    
            public bool Undo(string packageName, XmlNode xmlData)
            {
                string config = "~/Config/applications.config";
                XmlDocument appsFile = XmlHelper.OpenAsXmlDocument(config);
    
                XmlNode app = appsFile.SelectSingleNode("//add[@alias='YourSection']");
    
                if (app != null)
                {
    
                    appsFile.RemoveChild(app);
                    appsFile.Save(IOHelper.MapPath(config));
                }
    
                return true;
            }
    
            public XmlNode SampleXml()
            {
                var xml = "<Action runat=\"install\" undo=\"true\" alias=\"YourSection\" />";
                XmlDocument x = new XmlDocument();
                x.LoadXml(xml);
                return x;
            }
        }
    }
    

    Add in package.xml <Action runat="install" undo="true" alias="YourSection" />

  • Damien Holley 179 posts 540 karma points
    May 08, 2017 @ 08:14
    Damien Holley
    0

    cheers, will try that. in the Undo part of the code should that have //add? I would have thought a remove or something would be required.

    so ie: if my alias of the section is CHEESE would I have ...SelectSingleNode("//add[@alias='CHEESE']"); or would it be ...SelectSingleNode("@alias='CHEESE'");?

Please Sign in or register to post replies

Write your reply to:

Draft