umbraco - how to get all of nodes by Document Type

umbraco

Solution

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...

Problem

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?

Original source

Related problems