Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

umbraco - how to get all of nodes by Document Type

Tags:

umbraco

How can I get all nodes by specific Document Type?

For example, I want to get in code behind all of nodes with Document Type: s3Article. How can I do this?


New informations:

    IEnumerable<Node> nodes = uQuery.GetNodesByType("s3Article").Where(x => x.NiceUrl.Contains("en"));

    lvArticles.DataSource = nodes;
    lvArticles.DataBind();

This is my code. I had to use Where(x => x.NiceUrl.Contains("en")), because I have 2 language version- without Where I receive nodes from all catalogues with doctype s3Article, but I want to get only from one language version.

Problem is here:

<a href='<%# umbraco.library.NiceUrl(Tools.NumericTools.tryParseInt( Eval("id"))) %>'><%# Eval("title")%></a>
<%# Tools.TextTools.makeIMGHTML("../.."+ Eval("img").ToString(),"180") %>
<%# umbraco.library.StripHtml(Limit(Eval("Article"), 1000))%>
<%# Eval("author")%>

System.Web.HttpException: DataBinding: 'umbraco.presentation.nodeFactory.Node' does not contain a property named 'title'.

The same problem happens with the title, img, article, author. Only ID works nice. How to resolve it?

like image 389
whoah Avatar asked Oct 23 '25 12:10

whoah


1 Answers

You can use the uQuery GetNodesByType(string or int) method:

IEnumerable<Node> nodes = uQuery.GetNodesByType("s3Article");

Alternatively, you can use an extension method to get all descendant nodes and then query them by type as in the following answer:

Umbraco 4.6+ - How to get all nodes by doctype in C#?


You could use this to databind to a control within a usercontrol like so:

lvArticles.DataSource = nodes.Select(n => new {
    ID: n.Id,
    Title: n.GetProperty("title").Value,
    Author: n.GetProperty("author").Value,
    Article: n.GetProperty("article").Value,
    Image: n.GetProperty("img").Value,
});
lvArticles.DataBind();

Only you would need to strip the html, convert the image id to a url, etc. within the select statement as well...

like image 183
Douglas Ludlow Avatar answered Oct 27 '25 02:10

Douglas Ludlow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!