Recommended way of loading a Document object with it's "published" version.
I want to be able to load a Document object with the content of it's published version. See the method below for a better idea.
private Document GetPublishedDocument(int id) { Document doc = new Document(true, id); if (!doc.HasPendingChanges()) { return doc; }
foreach (var docVersion in doc.GetVersions().OrderByDescending(v => v.Date)) { var d = new Document(id, docVersion.Version); if (d.Published) { return d; } }
return null; }
Of course this code doesn't work because the Published() property doesn't reflect the status of the version of the Document loaded since it will return true if any version of the given Document has been published.
Can anybody with experience on the Umbraco API help me?
Recommended way of loading a Document object with it's "published" version.
I want to be able to load a Document object with the content of it's published version. See the method below for a better idea.
private Document GetPublishedDocument(int id)
{
Document doc = new Document(true, id);
if (!doc.HasPendingChanges())
{
return doc;
}
foreach (var docVersion in doc.GetVersions().OrderByDescending(v => v.Date))
{
var d = new Document(id, docVersion.Version);
if (d.Published)
{
return d;
}
}
return null;
}
Of course this code doesn't work because the Published() property doesn't reflect the status of the version of the Document loaded since it will return true if any version of the given Document has been published.
Can anybody with experience on the Umbraco API help me?
Hi Javier,
Why you don't use Node class ?
Node get the data which has been published and cached.
Article about difference between Document and Node below:
http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document
Maybe I misunderstood what you want.
Thanks,
Alexandr
Hi Alexandr
Please take a look at the documentService class located on the umbraco.webservices project.
My problem is that the relevant methods on the Document Service return the latest version of the document but I need the published version.
Take this method for example:
And this is how my new method looks so far:
While the code I wrote seems to be fine for now I'm not sure it is neither the recommended nor the most efficient way to accomplish what I need.
I'll explore the Node object and get back to you.
Thanks for your reply.
Javier
is working on a reply...