Copied to clipboard

Flag this post as spam?

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


  • Jonas 49 posts 21 karma points
    Apr 02, 2009 @ 14:46
    Jonas
    0

    Find document content by property Node.findByProperty(propertyname,value) ???

    Hi, I need to mirror content from another db (actually Filemaker, but I get the data via xml). And I prefer doing it with .net-code rather than with SQL. For that reason I need a way to find a document by a ID, which in Umbraco is just a regular property - not the node id and not the name.

    I rather not write a SQL Query, but I do think I can use NodeFactory.ChildrenAsTable. But I would like to ask you first if there was any other more direct method, like Node.findByProperty(propertyname,value) or something?

    Thanks!

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 02, 2009 @ 15:13
    Dan Diplo
    0

    You can right a quick method to do this farily easily in c#. Just iterate through all the nodes and add the ones with a matching property to a collection. You can iterate through nodes like this:
    [code]

    ...
    using umbraco.presentation.nodeFactory;
    ....

    public Nodes GetNodes()
    {
    Nodes myNodes = new Nodes();
    Node root = new Node(-1);
    myNodes.Add(root);

    IterateNodes(root.Children, myNodes);

    return myNodes;
    }

    private static void IterateNodes(Nodes nodes, Nodes myNodes)
    {
    foreach (Node n in nodes)
    {
    myNodes.Add(n);
    if (n.Children.Count > 0)
    IterateNodes(n.Children, myNodes);
    }
    }
    [/code]

    Just alter that to add a check for a property using the GetProperty() method of the Node.

  • Jonas 49 posts 21 karma points
    Apr 02, 2009 @ 15:26
    Jonas
    0

    Yes, thank you, I think I will go that way, but I still wonder if there is some method that internally uses a "sql select where @parameter=@value" to get the specific node.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 02, 2009 @ 15:31
    Dan Diplo
    0

    The Nodes in nodeFactory are cached in memory so iterating them should be very fast.

    However, there is also the Document class in the umbraco.cms.businesslogic.web namespace. This has various static methods which may be of use, such as Document.getContentOfContentType(). Check them out, it may help.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Apr 02, 2009 @ 15:38
    Dirk De Grave
    0

    Hi,

    If you're searching through published content, use xpath some sort of as a path expression which will resemble your sql much. If you're searching through the backend content (published/non published content), consider using Lucene search as all nodes are Lucene indexed. Fast and easy to implement

    Have a look at http://www.netaddicts.be/articles/umbraco-and-lucenenet.aspx

    Hope this helps.

    Regards,
    /Dirk

  • Jonas 49 posts 21 karma points
    Apr 02, 2009 @ 15:42
    Jonas
    0

    "The Nodes in nodeFactory are cached in memory", ah, I was just going to ask.

    "Lucene", wow cool!

    Thanks for your input!

    /back to the code

Please Sign in or register to post replies

Write your reply to:

Draft