Make Document Query API show unpublished docs in admin like TreeHelper.SelectNodes

SOS Childrensvillages asked on May 3, 2018 11:11

Hi, previously when we used the now obsolete method TreeHelper.SelectNodes() in a repeater, we could see unpublished/archived pages in the repeater when we were in the pages module.

Is there anyway we can get Document Query API to do this? We're not overly concerned whether it's using DocumentHelper.GetDocuments or TreeProvider.SelectNodes().

In K10, when I try to use these methods it acts correctly for the end user but displays the wrong items in the cms desk.

In K11, neither the end user page or cms desk show my unpublished pages.

I guess I could use a check to see if I'm in the live site or not and then call Published() on the document query API accordingly but that would double the size of my cache.

Recent Answers

Dragoljub Ilic answered on May 3, 2018 12:08 (last edited on May 3, 2018 12:09)


I'm not sure why you really want to show that, but you can cache all documents and then with simple LINQ take only published on the live site. Something like code bellow:

var allDocuments = DocumentHelper.GetDocuments().ToArray(); //cache this

And then when you take that from cache, add check for Live Site and do something like:

allDocuments.Where(doc => doc.IsPublished);

Best regards, Dragoljub

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on May 3, 2018 16:28 (last edited on May 3, 2018 20:33)

I guess you can do something like the code below. Published(false) retrieves all documents on the live site including archived and not yet published documents. You can put in where any sql condition you want

    var myUnpublishedDocs = DocumentHelper.GetDocuments().OnSite("CorporateSite").Published(false).Where("DocumentPublishTo < getdate() OR DocumentIsArchived = 1 ");
                if (myUnpublishedDocs.HasResults()) {
                    DataTable yourUnpublhsedDocs = myUnpublishedDocs.Result.Tables[0];
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.