Copied to clipboard

Flag this post as spam?

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


  • Lee 1123 posts 3059 karma points
    Apr 07, 2010 @ 13:30
    Lee
    0

    Find Out NodeID/URL By Property Value

    I'm trying to get a node ID by a property value, basically to cut a long story short - I get passed an ID by an external system

    thepagename?id=654654

    I have a property on each node filled with these unique values, but I need to be able to lookup the NodeID from this property value - As I need to get the node URL so I can redirect the user to the correct page (Hope that makes sense..lol)

    All these nodes are a specific DocType, so was wondering if anyone new a nice and easy way of doing this?

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Apr 07, 2010 @ 13:40
    Jan Skovgaard
    0

    Hi Lee

    I think you should be able to use the umbraco.library in C# so I think you can get the corresponding nodes by using the "getXmlNodeById" extension.

    /Jan

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Apr 07, 2010 @ 13:50
    Dirk De Grave
    3

    Hi Lee,

    Me thinks GetXmlNodeByXPath() which is part of the umbraco.library class should do the trick. Just need to assemble the correct xpath expression... Returns an XPathNodeIterator object

    //node [@nodeTypeAlias = 'specificDocType' and string(./data [@alias = 'propertyAlias']) = 'id']

    (may need to tweak the xpath a bit...)

     

    Hope this helps.

    Regards,

    /Dirk

     

     

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Apr 07, 2010 @ 13:50
    Dirk De Grave
    0

    Or, use Linq2umbraco if you're using v4.1

     

    /Dirk

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Apr 07, 2010 @ 13:56
    Lee Kelleher
    0

    Dirk beat me to it with the XPath query! :-)

    If you did want to go the XSLT extension route, then you could use the following SQL query?

    SELECT DISTINCT
        d.contentNodeId
    FROM
        cmsPropertyData AS d
        INNER JOIN cmsPropertyType AS t ON d.propertytypeid = t.id
    WHERE
        t.Alias = 'externalPageId'
        AND
        d.dataNvarchar = '654654'

    Where the 'externalPageId' is the property type alias.

    Personally, I'd go with the XPath option... that is if you are using XSLT! ;-)

    Cheers, Lee.

  • Lee 1123 posts 3059 karma points
    Apr 07, 2010 @ 14:20
    Lee
    0

    Replies very appreciated chaps - Thanks :)

    TBH I had the XSLT to do it already, but the reason I was trying to use the API and not XSLT is I need to redirect the user to the nodes URL after I get it - I didn't think that was possible with XSLT?

    @Lee - Is this type of call not possible using the nodefactory?

    @Dirk - Its 4.03 :(

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Apr 07, 2010 @ 14:25
    Lee Kelleher
    1

    Hi Lee,

    I've been referring to this a lot lately, (but haven't used it myself) ... take a look at Hendy's Umbraco Helper Class, there is a method called "GetNodesFromXpath", which will return you a nodeFactory class.

    Quick snippet:

    public static List<Node> GetNodesFromXpath(string xPath)
    {
        List<Node> nodes = new List<Node>();
    
        XPathNavigator xPathNavigator = umbraco.content.Instance.XmlContent.CreateNavigator(); //get all umbraco xml
        XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPath); //TODO: check xpath string is valid
    
        int id;
        Node node;
    
        while (xPathNodeIterator.MoveNext())
        {
            if (int.TryParse(xPathNodeIterator.Current.Evaluate("string(@id)").ToString(), out id)) //check id is a numberic
            {
                node = new Node(id);
                if (node != null) { nodes.Add(node); }
            }
        }
    
        return nodes;
    }

    Cheers, (the other) Lee.

  • Lee 1123 posts 3059 karma points
    Apr 07, 2010 @ 14:43
    Lee
    0

    Man that class is awesome :)  Cheers dude!

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    May 13, 2010 @ 11:05
    Hendy Racher
    2

    Hi, just thought I'd mention that the class has been updated, as per the suggestion that GetNodesFromXpath method should parse for "$currentPage".

  • 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