DocumentQuery API to find unpublished

Ralph McLemore asked on September 11, 2014 05:02

in the example

var news = DocumentHelper.GetDocuments("CMS.News") 
.OnSite("CorporateSite") 
.Path("/News", PathTypeEnum.Children) 
.Published();

it will find only published pages (and you can put false to find all). is there an opposite? to find only archived or unpublished documents?

Correct Answer

Ralph McLemore answered on September 11, 2014 07:16

I figured it out. .WhereEquals("Published", 0)

0 votesVote for this answer Unmark Correct answer

Recent Answers


Martin Danko answered on September 12, 2014 11:16

Hello Ralph,

you should be also able simply to use the false parameter with Published() method:

var news = DocumentHelper.GetDocuments("CMS.News") 
.OnSite("CorporateSite") 
.Path("/News", PathTypeEnum.Children) 
.Published(false);

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Yev Fes answered on September 17, 2015 17:18

Martin, is this true?

Does .Published(false) retrieve JUST the unpublished documents, or published AND unpublished?

From my tests its both published and unpublished.

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on October 7, 2015 15:00

Hello Yev,

that's correct. This DocumentQuery Parameters is equivalent to "SelectOnlyPublished" parameter of API method -> SelectNodes. I agree, that it could be confusing at the very first sight when you thing that it's setting the value for retrieving published/unpublished documents but in fact it's just setting the value of API method. So it's correct behavior.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Saurav Kumar answered on March 28, 2017 09:07

Hi Martin,

How do I retrieve documents which are not just Published, but also in the PUBLISHED state of the workflow?
So all in all, only those documents which are in the published state.

Regards,
Saurav

0 votesVote for this answer Mark as a Correct answer

Saurav Kumar answered on November 28, 2017 14:18

Adding the steps to retrieve documents which are only in the published step

var publishedSteps = WorkflowStepInfoProvider.GetWorkflowSteps()

.WhereEquals("StepID", CMS.DataEngine.WorkflowStepTypeEnum.DocumentPublished) .Column("StepID");

query.WhereIn("DocumentWorkflowStepID", publishedSteps);

2 votesVote for this answer Mark as a Correct answer

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