Copied to clipboard

Flag this post as spam?

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


  • Fergus Davidson 309 posts 588 karma points
    Dec 20, 2011 @ 22:41
    Fergus Davidson
    0

    Convert uComponents MultiNodeTreePicker data from csv to xml

    hi

    i have about 1000 documents which have a property which uses the uComponents MultiNodeTreePicker with CSV data format.

    what i would like to do, for consistency with other document types, is convert from csv to xml.

    i am happy to add a new property to help with this, but i was hoping someone might have a bit of code lying around which will help me to transform from csv to xml.

    i am under the cosh time-wise so would appreciate any help, sql, .net anything would be great.

    thanks

  • Tim 1193 posts 2675 karma points MVP 5x c-trib
    Dec 21, 2011 @ 11:49
    Tim
    0

    I would have thoght that the easiest way to do this would be a SQL script to chnage the format of the data, followed by a site republish to regenerate the XML file so the data is in the new format. I'm guessing you may need to update a few macros as well to account for the new format!

    I'm not 100% on the exact query that you'd need to write, but the tables that you're interested in are cmsPropertyType and cmsPropertyData. The second contains the actual property data. It goes without saying that you should take a copy of your database and test this on the copy of the database rather than doing this kid of thing directly on the live database!

    You can use the cmsPropertyType table to find the properties to change by their alias, and then join that to the cmsPropertyData table to get the value that you'll need to replace.

    Hope that helps!

  • Fergus Davidson 309 posts 588 karma points
    Dec 21, 2011 @ 14:39
    Fergus Davidson
    0

    thanks Tim, i may have to try something like that.

    In the meantime, i have cobbled together the following [DOES NOT WORK!]

    i am not a coder and cannot work out why this does not work, or what i should do - can anyone help??

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.ApplicationBlocks.Data;
    using System.Data.SqlClient;
    using System.Data;
    using System.Configuration;
    using umbraco.presentation.nodeFactory;
    using umbraco.cms.businesslogic.web;
    using umbraco.BusinessLogic;
    using umbraco;
     
    namespace umbracoDocumentApi
    {
        public partial class XPathCheckBoxListChangeCsvToXml : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DocumentType dt = DocumentType.GetByAlias("DocumentXXX");
                var docIds = Document.getAllUniqueNodeIdsFromObjectType(dt.UniqueId);
                foreach (var docId in docIds)
                {
                    var doc = new Document(docId);
                    var sectorFilterCSV = doc.getProperty("sectorFilter").ToString();

                    

                    string[] splitCSV = sectorFilterCSV.Split(',');
     
                    var sectorFilterXML = "<XPathCheckBoxList>";
                    foreach (string s in splitCSV)
                    {
                        sectorFilterXML = sectorFilterXML + "<nodeId>" + s + "</nodeId>";
                    }
                    sectorFilterXML = sectorFilterXML + "</XPathCheckBoxList>";
     
     
     
                    doc.getProperty("sectorFilterXML").Value = sectorFilterXML;
                    doc.Publish(Page.User as User);
                    library.UpdateDocumentCache(docId);
     
                }
            }
    }
    }
  • Fergus Davidson 309 posts 588 karma points
    Dec 21, 2011 @ 16:18
    Fergus Davidson
    1

    Finally, managed to find various posts/code/etc that helped with this.

    the code i ended up with, which did work for me is:

    using System;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
     
     
    namespace umbracoDocumentApi
    {
        public partial class XPathCheckBoxListChangeCsvToXml : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
                litResult.Text = "";
                litResult.Text = litResult.Text + "start:<br />";
     
     
                var type = DocumentType.GetByAlias("Document");
                Content[] docIds = Document.getContentOfContentType(type);
     
               litResult.Text = litResult.Text + "docIds: " + docIds + "<br />";
     
                foreach (var content in docIds)
                {
                    var sectorFilterCSV = content.getProperty("sectorFilter").Value.ToString();
                    
                    string[] splitCSV = sectorFilterCSV.Split(',');
     
                    var sectorFilterXML = "<XPathCheckBoxList>";
                    foreach (string s in splitCSV)
                    {
                        sectorFilterXML = sectorFilterXML + "<nodeId>" + s + "</nodeId>";
                    }
                    sectorFilterXML = sectorFilterXML + "</XPathCheckBoxList>";
     
     
     
                    content.getProperty("sectorFilterXML").Value = sectorFilterXML.ToString();
                    content.getProperty("test").Value = sectorFilterXML.ToString();
                    content.Save();
                    
     
                }
            }
        }
    }
  • 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