How to unpublish a page using kentico API

GTEK IT DEV Team asked on March 18, 2019 12:09

How can i unpublish a page using kentico API from code behind, please?

Recent Answers


David te Kloese answered on March 18, 2019 12:28

You could set the publish to field of a node:

nodex.DocumentPublishTo = DateTime.MinValue;
nodex.Update(); //save it to DB

Or when using workflow:

page.Archive("This is a comment - the page is obsolete, archiving.");

Find more API examples in the documentation: docs.kentico.com/api12/content-management/page-workflow-and-versioning

1 votesVote for this answer Mark as a Correct answer

GTEK IT DEV Team answered on March 19, 2019 03:55 (last edited on March 19, 2019 03:59)

Hi David te Kloese,


I used your code


nodex.DocumentPublishTo = DateTime.MinValue;
nodex.Update();

But the publish to field has set to null. And after that. I used following code

nodex.DocumentPublishTo = DateTime.Now.AddDays(-10);
nodex.Update();

And now the publish to have value. But i still can access the page from front end site.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on March 19, 2019 07:40

It looks like you are using workflows, is this correct? If yes, you need to realize the difference between workflow and content scheduling.
So, if you are using just workflow, you can move the page to archived step.
If you are not using workflow, as David said, set the DocumentPublishTo field to a past date.

If you are using both, set the DocumentPublishTo to a past date and move the page to the Published step of the workflow at the same time. And then, you can also move it to the archived step if you want to.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on March 19, 2019 09:16

Also make sure you're not using viewing the live site in the same browser as where you are logged on into the admin interface.Since when logged in you can see unpublished content. Best to use a incognito or different browser.

0 votesVote for this answer Mark as a Correct answer

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