Copied to clipboard

Flag this post as spam?

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


  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 12:15
    Advay Pandya
    0

    Fetching all nodes of Umbraco by name using code behind C# pages

    Hello All,

    I want to find a way to fetch all the Umbraco nodes by name using  code behind C#  pages, just like the way we are fetching a single node as shown in below code snippet:

    IEnumerable<Node> nodes = uQuery.GetNodesByName("Page A");

     

    Please advise.

    Please let me know if I am missing something or I didnt explin properly.

    Thanks

    Advay Pandya

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 12:29
    Dave Woestenborghs
    0

    Hi Advay,

    Can I ask why you are trying to retrieve nodes by name ? The name of a node can be changed by a editor and then your code will not work :-)

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 12:49
    Advay Pandya
    0

    Hi Dave

    Thanks For your Reply.. :)  But right now there is not issue about Change by Someone my point is to Find NodeName from All Pages.. 

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 12:51
    Dave Woestenborghs
    0

    Now it's not clear to me.

    Do you want to get the node names of all pages or do you want to find an page by name ?

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 12:59
    Advay Pandya
    0

    Hi Dave,

    I mean to say I need all published node details in code behind.

    Means whole content  tree.

    Please advise.

    Please let me know if I am missing something or I didnt explin properly.

    Thanks

    Advay Pandya

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 13:01
    Dave Woestenborghs
    0

    What do you want to do with all nodes ? Can you explain what you are trying to achieve. Maybe there is a better solution for your case than getting all nodes.

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 13:14
    Advay Pandya
    0

    Hi Dave,

    I have a "News and Event" page.

    My content editor needs that if any of the page having "displayInNews" check box checked than it  will show that page of content.

    So I need to check all the nodes using loop(foreach).

     

    This section will appear in all the content pages.

    So I want to check from code behind that which page have that checkbox checked.

    Please let me know if you still want more clarity for the same.

    Please advise.

    Thanks

    Advay Pandya

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 13:20
    Dave Woestenborghs
    0

    So let me check if get it right.

    You have a document type called "News and Event" page that has a checkbox called "displayInWebsite".

    On other place in your website you want to show all "News and Event" pages that have this checkbox checked ?

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 13:26
    Advay Pandya
    0

    Hi Dave,

    Not exactly.

    I have that checkbox in my all the document types in my umbraco syatem.

    I want to show all the document types in which that checkbox is checked,  inside the  "News and Event" page.

    Please advise.

    Please let me know if I am missing something or I didnt explin properly.

    Please advise.

    Thanks

    Advay Pandya

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 13:36
    Dave Woestenborghs
    0

    I think this query will achieve what you want. You can try it in your view

    @{
        var list = Umbraco.TypedContentAtRoot().First().DescendantsOrSelf().Where(x =>
            {
                if (x.HasProperty("displayInNews") && x.HasValue("displayInNews"))
                {
                    if (x.GetPropertyValue<int>("displayInNews") == 1)
                    {
                        return true;
                    }
                }
                return false;
            }).ToContentSet();
    }

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 14:06
    Advay Pandya
    0

    Hi Dave,

    Do you refer C# code behind ?

    I am using Umbraco v6.0.5. I am not able to find "TypedContentAtRoot()" method in the "Umbraco".

    Do I need to use any assembly ?

    Please let me know if I am missing something.

    Please advise.

    Thanks

    Advay Pandya

     

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 14:31
    Dave Woestenborghs
    0

    Ah..you can do this

    var helper = new UmbracoHelper(UmbracoContext.Current);

    and then helper.TypedContentAtRoot()

     

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 15:24
    Advay Pandya
    0

    Hi Dave,

    Thanks for your suggestion.

    We tried with the given solution. We got the helper object too, but still we didnt get "TypedContentAtRoot()" method in the helper object.

    Please advise.

    Please let me know if I am missing something.

    Thanks

    Advay Pandya

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 15:31
    Dave Woestenborghs
    0

    Hmm..strange what version are you using ?

    Dave

  • Advay Pandya 11 posts 71 karma points
    Oct 20, 2014 @ 15:34
    Advay Pandya
    0

    Hi Dave,

    We are using Umbraco v6.0.5.

     

    Thanks

    Advay Pandya 

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 20, 2014 @ 15:40
    Dave Woestenborghs
    0

    If i'm correc the method should be present in that version

  • Doron Uziel 23 posts 93 karma points
    Oct 20, 2014 @ 19:54
    Doron Uziel
    0

    Hi,

    You will probably want to use XPath as this is the fastest approach.

    If I understand correctly you are using webforms macro, so I suggest uQuery:

    var newsItems = uQuery.GetNodesByXPath("//*[@isDoc and displayInWebsite=1]");

    Hope I helped.

    Doron

  • Urvish 252 posts 776 karma points
    Oct 21, 2014 @ 07:07
    Urvish
    100

    Hi Advay,

    Please find below code line.

    IEnumerable

    you will get whole content tree node from in this IEnumerable.

    Hope this works for you.

    Regards,

    Urvish Mandaliya

  • Advay Pandya 11 posts 71 karma points
    Oct 21, 2014 @ 07:13
    Advay Pandya
    0

    Hi Urvish and Doron,

    The solution you provided worked for me.

    Thank you for the solution.

    Dave, Thanks for your kind support.

    Thanks

    Advay Pandya 

Please Sign in or register to post replies

Write your reply to:

Draft