GET /blog/Functions-Publishing-a-document.md text/markdown back to the human version
---
title:        "Functions: Publishing a document"
description:  "Below you can find the code for publishing a document in Kentico."
url:          https://www.jeroenfurst.nl/blog/Functions-Publishing-a-document
date:         2010-11-25
category:     API and customisation
tags:         [API and customisation]
reading_time: 1
---

# Functions: Publishing a document

> Below you can find the code for publishing a document in Kentico.

Below you can find the code for publishing a document in Kentico.

```
// Initialize the TreeProvider
CMS.SiteProvider.UserInfo ui = CMSContext.CurrentUser;
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);        

// Check out the document
CMS.WorkflowEngine.VersionManager vm = new CMS.WorkflowEngine.VersionManager(tree);
vm.CheckOut(node);

// Update the node
node.SetValue("...", "...");
DocumentHelper.UpdateDocument(node, tree);

// Check in the document
vm.CheckIn(node, null, null);

// Get the current step of the document
CMS.WorkflowEngine.WorkflowManager wm = new CMS.WorkflowEngine.WorkflowManager(tree);
CMS.WorkflowEngine.WorkflowStepInfo currentStep = wm.GetStepInfo(node);

// Loop through the steps and publish the document
while ((currentStep != null) && (currentStep.StepName.ToLower() != "published"))
{
    currentStep = wm.MoveToNextStep(node, "");
}
```