Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1494 posts 1635 karma points c-trib
    Jun 29, 2016 @ 16:40
    Biagio Paruolo
    0

    Dashboard.config: How to add <section> dinamically?

    How to add

    dinamically to dashboard.config file without to manually add section when install a plugin o a custom section?

  • Paulius Putna 78 posts 136 karma points
    Jun 29, 2016 @ 19:38
    Paulius Putna
    1

    Hi Biagio,

    I used the snippet below to achieve this:

        public void AddDashboard()
        {
            var saveFile = false;
            var dashboardPath = "~/config/Dashboard.config";
            var dashboardFilePath = HostingEnvironment.MapPath(dashboardPath);
    
            XmlDocument dashboardXml = new XmlDocument();
    
            if (dashboardFilePath != null)
            {
                dashboardXml.Load(dashboardFilePath);
    
                XmlNode findSection = dashboardXml.SelectSingleNode("//section [@alias='ErrorMonitorSection']");
    
                if (findSection == null)
                {
                    const string xmlToAdd = "<section alias='ErrorMonitorSection'>" +
                                            "<areas>" +
                                            "<area>developer</area>" +
                                            "</areas>" +
                                            "<tab caption='Error Monitor'>" +
                                            "<control addPanel='true' panelCaption=''>/App_Plugins/ErrorMonitor/views/errormonitor.dashboard.html</control>" +
                                            "</tab>" +
                                            "</section>";
    
                    XmlNode dashboardNode = dashboardXml.SelectSingleNode("//dashBoard");
                    if (dashboardNode != null)
                    {
                        XmlDocument xmlNodeToAdd = new XmlDocument();
                        xmlNodeToAdd.LoadXml(xmlToAdd);
    
                        var toAdd = xmlNodeToAdd.SelectSingleNode("*");
                        if (dashboardNode.OwnerDocument != null)
                            dashboardNode.AppendChild(dashboardNode.OwnerDocument.ImportNode(toAdd, true));
    
                        saveFile = true;
                    }
                }
    
                if (saveFile)
                {
                    dashboardXml.Save(dashboardFilePath);
                }
            }
        }
    

    Hope that helps.

    Paulius

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies