I'm currently doing some work with the umbraco API and i read in the API Reference that when working at the back end, it is recommended to use Documents, whereas Nodes are preferable at the front end. Given the points in the reference, this makes sense.
Now, when working at the back end, i need to get a set of Documents with a specific document type. All the examples i've found to do this work with Nodes and the nodeTypeAlias property. The C# Document type has no similar property. The only thing i found was "Template" but i need to search on Document Type.
Whilst looping through a set of Documents, i thought i could get the Node representation and then i would have access to the nodeTypeAlias property. I assumed the Ids would be the same for the Document and the node so i did this:
Node n = new Node(document.Id)
However, this just returns an empty node.
What i want to know is:
a) Is there are nicer way to query documents by document type ? b) Am i right in assuming that the method above should give me the node representation of that document and if not, is there a way to do this?
Never used it myself but it appears (from the source) that there is a static method on the Document class called GetDocumentsOfDocumentType(int docTypeId) Should do the trick?
Ah i didnt notice that method there, that'll do the trick!
The only thing is, i'd like to get all documents of a specific document type under a particular node, to save iterating through the documents that i know for sure arent going to be returned. But thanks for pointing that method out, that'll get me started!
Well the ID is the node ID, so if you don't mind hardcoding it, you can get the ID by hovering over the DocumentTypes node in the UI and getting the ID from the link url. Otherwise you can get a DocumentType object like this (this is untested):
Get Documents by Document type with API
I'm currently doing some work with the umbraco API and i read in the API Reference that when working at the back end, it is recommended to use Documents, whereas Nodes are preferable at the front end. Given the points in the reference, this makes sense.
Now, when working at the back end, i need to get a set of Documents with a specific document type. All the examples i've found to do this work with Nodes and the nodeTypeAlias property. The C# Document type has no similar property. The only thing i found was "Template" but i need to search on Document Type.
Whilst looping through a set of Documents, i thought i could get the Node representation and then i would have access to the nodeTypeAlias property. I assumed the Ids would be the same for the Document and the node so i did this:
Node n = new Node(document.Id)
However, this just returns an empty node.
What i want to know is:
a) Is there are nicer way to query documents by document type ?
b) Am i right in assuming that the method above should give me the node representation of that document and if not, is there a way to do this?
Thanks
Never used it myself but it appears (from the source) that there is a static method on the Document class called GetDocumentsOfDocumentType(int docTypeId)
Should do the trick?
Ah i didnt notice that method there, that'll do the trick!
The only thing is, i'd like to get all documents of a specific document type under a particular node, to save iterating through the documents that i know for sure arent going to be returned. But thanks for pointing that method out, that'll get me started!
After looking around, im unsure how i can get the id of the DocType, the umbraco back end only shows the alias of the doc type.
Well the ID is the node ID, so if you don't mind hardcoding it, you can get the ID by hovering over the DocumentTypes node in the UI and getting the ID from the link url. Otherwise you can get a DocumentType object like this (this is untested):
and then use that in your call to GetDocumentsOfDocumentType, like this
Thanks Alex, thats done the trick!
is working on a reply...