Copied to clipboard

Flag this post as spam?

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


  • jigar 169 posts 232 karma points
    Jul 22, 2009 @ 15:31
    jigar
    0

    How to get all node of specific type using Node factory?

    How to get all node of specific type using Node factory?


    Hi I am little new to use node factory class. I want to know is there any way to fetch nodes on bases of their type and order them on basis of their property.


    I am coding in C# and looking for something like…

         Nodes MyNodes = new Nodes();
         MyNodes = NodeFactory.GetAllNodes(‘Events’).Orderby(“EventEndDate”)     

    Please help me in this.

    Regards

    Jigar

     

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 15:55
    Dirk De Grave
    0

    Hi,

     

    Me thinks you're really into linq... might have to wait for linq2umbraco to make such calls :p

     

    Anyways, you could also use some smart xslt to get the same results:

    -Build an xslt file that does the filtering and the sorting of the nodes

    -Transform the cached xml content against the xslt using the .net api's such as the XslCompiledTransform class.

     

    Hope this helps.

    Regards,

    /Dirk

  • jigar 169 posts 232 karma points
    Jul 22, 2009 @ 16:08
    jigar
    0

    All right Dirk De Grave,

    I am fine without linq. just give me some code snipet that works fine for above.  I just want to loop through nodes of certain types. i would do ordering manually.

    i have certain code for this tasks (found from forum only) but not working.

    umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(1158);
    umbraco.presentation.nodeFactory.Nodes childrenNodes = node.Children;

    this gives error to me.

    Any help would be appriciated.

    Regards,

    Jigar

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 22, 2009 @ 16:35
  • Murray Roke 467 posts 875 karma points c-trib
    Jul 28, 2009 @ 23:08
    Murray Roke
    0

    I've just added a howto article in  the wiki that may help.

    when using those extension methods you can write the following: (not tested)

    Node MyNode = new Node(123);
    var events = MyNode.AllChildren().Where(n => n.NodeTypeAlias == "Events").OrderBy(n => n.GetPropertyAsDateTime("EventEndDate"));

    Hope that helps.

  • Petr Snobelt 923 posts 1534 karma points
    Jul 29, 2009 @ 08:29
    Petr Snobelt
    0

    Or you can use ChildrenAsTable (which then can be sorted or filtered)

    Node MyNode = new Node(123);
    DataTable = MyNode.ChildrenAsTable("nodeType");

    Maybe it loads all childs in single query and may be faster.

    Petr

  • 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