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:
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.
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
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
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..
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
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
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
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
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
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
I think this query will achieve what you want. You can try it in your view
Dave
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
Ah..you can do this
var helper = new UmbracoHelper(UmbracoContext.Current);
and then helper.TypedContentAtRoot()
Dave
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
Hmm..strange what version are you using ?
Dave
Hi Dave,
We are using Umbraco v6.0.5.
Thanks
Advay Pandya
If i'm correc the method should be present in that version
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
Hi Advay,
Please find below code line.
you will get whole content tree node from in this IEnumerable.
Hope this works for you.
Regards,
Urvish Mandaliya
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
is working on a reply...