Copied to clipboard

Flag this post as spam?

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


  • Ansar 181 posts 291 karma points
    Jan 07, 2012 @ 19:42
    Ansar
    0

    How to get value from Multi Node Tree Picker using C#

    Trying to do a bit complex page usinbg Usercontrol with C#.. Can anyone please tell me how to get the node ids from Multi Node Tree Picker... The Property Value is as follows

    <MultiNodePicker>
    <nodeId>1285</nodeId>
    </MultiNodePicker>

    I want to get the nodeId using C#.. Please help

     

  • Mads Krohn 211 posts 504 karma points c-trib
    Jan 09, 2012 @ 00:43
    Mads Krohn
    0

    Hey there

    When using C# to access the MNTP values, is is easier to retrive the values as csv.
    You can change the output behavior on the datatype.
    Then, instead of getting some xml returned you will simply get a string like so: "1285,3233,5443".
    Let me know if you have more questions regarding this.

    Hope this helps.

    /Mads

  • Ansar 181 posts 291 karma points
    Jan 09, 2012 @ 06:26
    Ansar
    0

    Hi Mads,

    Thank you for your reply.. yes thats a nice option and it will be really easy..  but unfortunately we already have a number of XSLT functionalities based on the MNTP XML output structure and changing it to CSV will break it all.. The only option for me now is to read it from XML..

    But the good news is that I have already found a way for this using XPathNodeIterator


    private string getValueFromTreePicker(String mntpXml)
    {
    byte[] byteArray = new byte[mntpXml.Length];
    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    byteArray = encoding.GetBytes(mntpXml);
    MemoryStream memoryStream = new MemoryStream(byteArray);
    memoryStream.Seek(0, SeekOrigin.Begin);


    XPathDocument document = new XPathDocument(memoryStream);
    XPathNavigator navigator = document.CreateNavigator();

    XPathNodeIterator nodes = navigator.Select("/MultiNodePicker/nodeId");
    nodes.MoveNext();
    XPathNavigator nodesNavigator = nodes.Current;

    XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

    string s = "";
    while (nodesText.MoveNext())
    s+= "," + nodesText.Current.Value;



    return s.TrimEnd(",".ToCharArray());
    }

     

  • Mads Krohn 211 posts 504 karma points c-trib
    Jan 09, 2012 @ 11:12
    Mads Krohn
    0

    Ahh ok, I see, good that you found a solution :)

Please Sign in or register to post replies

Write your reply to:

Draft