Copied to clipboard

Flag this post as spam?

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


  • Max Mumford 266 posts 293 karma points
    Sep 06, 2011 @ 17:21
    Max Mumford
    0

    CS: Getting number of nodes with specific properties

    Hi all,

    I need to count the number of nodes that have a specific property value in a csharp user control.

    The nodes that i need to count live under a sibling of the node that the usercontrol will be rendered on.

    The following xPath gets the nodes that I need:

    $currentPage/../child::AdminContainer/Admin[@isDoc]

    How do I get them and count them in csharp using the umbraco api?

    I have tried using umbraco.library.GetXmlNodeByXPath but I cannot use the $currentPage variable in cs.

    Thanks,

    Max.

  • Max Mumford 266 posts 293 karma points
    Sep 06, 2011 @ 17:23
    Max Mumford
    0

    Sorry, xPath should be:

    $currentPage/../child::AdminContainer/Admin[@isDoc and x = 1 and y = 2]

    (to check node property values)

  • Max Mumford 266 posts 293 karma points
    Sep 08, 2011 @ 18:25
    Max Mumford
    0

    I found a solution and did update the documentation for the GetXmlNodeByXPath method here:

    http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyxpath

    But for some reason it has been rolled back to the original edit... I would try to roll it forwards but the history functionality dosn't seem to be working in chrome firefox or IE at the moment :/

    Here is the code I used:

    XPathNodeIterator otherAgencyAdmins = umbraco.library.GetXmlNodeByXPath("//Admin[@isDoc and agencyID = '" + agencyId + "']");
    
    System.Collections.IEnumerator otherAgencyAdminsEnumerator = otherAgencyAdmins.GetEnumerator();
    while (otherAgencyAdminsEnumerator.MoveNext())
    {
        XPathNavigator CurrentNode = (XPathNavigator)otherAgencyAdminsEnumerator.Current;
        String strAdminRecordId = CurrentNode.GetAttribute("id", String.Empty);
        //do something with node id
    }
  • Max Mumford 266 posts 293 karma points
    Sep 08, 2011 @ 18:26
    Max Mumford
    0

    Note: The $currentPage variable is unavailable in the c# context as the umbraco namespaces and xslt extensions have not been loaded.

Please Sign in or register to post replies

Write your reply to:

Draft