If you're using C#, these Extension Methods I wrote might be helpful to you:
/// <summary>
/// Returns all child nodes with the specified nodeTypeAlias, starting from the current node
/// </summary>
/// <param name="node">The node from where to search</param>
/// <param name="nodeTypeAlias">The nodeTypeAlias to search for</param>
/// <param name="recursive">True to search in all descendant, false to search only in children</param>
/// <returns>A collection of nodes with the specified nodeTypeAlias</returns>
public static IEnumerable<Node> GetNodesByTypeFromCurrent(this INode node, string nodeTypeAlias, bool recursive = false)
{
if (node == null)
throw new ArgumentNullException("node");
if (recursive)
return node.GetDescendantNodes().Where(x => x.NodeTypeAlias == nodeTypeAlias);
return node.GetChildNodes().Where(x => x.NodeTypeAlias == nodeTypeAlias);
}
/// <summary>
/// Returns all descendant nodes
/// </summary>
/// <param name="node">The node</param>
/// <param name="includeCurrent">Include the current node in the result</param>
/// <returns>All descendant nodes</returns>
public static IEnumerable<Node> GetDescendantNodes(this INode node, bool includeCurrent = false)
{
if (node == null)
throw new ArgumentNullException("node");
if (includeCurrent)
yield return (Node)node;
foreach (Node child in node.GetChildNodes())
{
yield return child;
foreach (Node subchild in child.GetDescendantNodes())
{
yield return subchild;
}
}
}
/// <summary>
/// Returns the child nodes of this node
/// </summary>
/// <param name="node">The node</param>
/// <returns>The child nodes</returns>
public static IEnumerable<Node> GetChildNodes(this INode node)
{
if (node == null)
throw new ArgumentNullException("node");
return node.ChildrenAsList.Cast<Node>();
}
Difference between a Document and a Node is that a Document is used for write operations and a Node is read-only (cached). There's more info about this on the wiki.
Allways use a Node when the purpose is displaying stuff on a webpage for example.
What technique are you using for developing webpages? XSLT? Razor/MVC? Usercontrols/masterpages?
Usercontrols and masterpages I am using, razon/mvc weren't around when I last delved into anything and can't seem to do what I want in xslt.
I am just trying to filter by properties of the pages based on a search param that the user enters in a txt box.
The pages I need to filter are of one document type.
Note that the ContentService will potentially return unpublished nodes and it will hit the database. You typically want to work with UmbracoHelper and the extension methods on IPublishedContent (in an Umbraco view, you typically have access to Model.Content, which is an IPublishedContent), which will only work with the cached nodes. Unless you know what you are doing, avoid the convent service.
New way to get all documents by type
Hi
I have been away from Umbraco (and programming) for a long while and now I'm back, Umbraco's changed.
I want to get all documents by a document type and access all their properties.
I can't remember the way I used to do this, nor find any documentation of how to do it now as I can see somethings like DocumentType are now obselete?
I am using Umbraco 6.1.6 (the last version I used was 4. something..)
If you're using C#, these Extension Methods I wrote might be helpful to you:
@kipusoep Thanks for your quick reply.
This is a bit more in depth than I need I think. Can you still do something like List
All I have is the document type alias.
Can you refresh me, what's the difference between a node and document?
Difference between a Document and a Node is that a Document is used for write operations and a Node is read-only (cached). There's more info about this on the wiki.
Allways use a Node when the purpose is displaying stuff on a webpage for example.
What technique are you using for developing webpages? XSLT? Razor/MVC? Usercontrols/masterpages?
Usercontrols and masterpages I am using, razon/mvc weren't around when I last delved into anything and can't seem to do what I want in xslt. I am just trying to filter by properties of the pages based on a search param that the user enters in a txt box. The pages I need to filter are of one document type.
myNode.DescendantsOrSelf("noteType")
or
ContentService.GetContentOfContentType(ContentTypeService.GetContentType("myType").Id)
Where the first is a node. The second is using the newer api.
Note that the ContentService will potentially return unpublished nodes and it will hit the database. You typically want to work with UmbracoHelper and the extension methods on IPublishedContent (in an Umbraco view, you typically have access to Model.Content, which is an IPublishedContent), which will only work with the cached nodes. Unless you know what you are doing, avoid the convent service.
It is perfectly reasonable to want to query all nodes published or not e.g. for reporting purposes in the back office.
is working on a reply...