from d in Document.GetDocumentsOfDocumentType((int)DocumentType.JOB) where d.Published && !d.IsTrashed select d // where document is umbraco.cms.businesslogic.web.Document
i.e., I get all the current "job" documents for display in a list.
Unfortunately, I get a lot of "duplicate" documents in the returned list. For example, I get the "same" document with ID 1575, 1568, 1601... etc. I think that most of these are previous revisions of the document.
Does anyone know how I would change this code to only get "current" documents? I should probably be using something in the "Node" interface for this, but I didn't see a Node.GetNodesOfNodeType method?
That should do it. Not as pretty, and you could probably using LinqToXml instead to make it a little neater. I haven't come across an umbraco library method to do this, but there may be one in uComponents?
Getting all current nodes instead of all current documents
Hi all;
I have some C# code like the following:
i.e., I get all the current "job" documents for display in a list.
Unfortunately, I get a lot of "duplicate" documents in the returned list. For example, I get the "same" document with ID 1575, 1568, 1601... etc. I think that most of these are previous revisions of the document.
Does anyone know how I would change this code to only get "current" documents? I should probably be using something in the "Node" interface for this, but I didn't see a Node.GetNodesOfNodeType method?
My Umbraco version is 4.6.1.
Bah. Now I have to write all that out again. So here goes:
Just using
should work ( at least it does in 4.7). To get the results you are after from the Node framework, you need to write some xpath and check the results:
That should do it. Not as pretty, and you could probably using LinqToXml instead to make it a little neater. I haven't come across an umbraco library method to do this, but there may be one in uComponents?
- Rob.
OK, my bad, the original code works fine - my bug was elsewhere.
I'm an idiot, sorry for any confusion. :)
is working on a reply...