This example shows how to update a versioned document (document with workflow). Workflow and the versioning are very closely connected, there should be always a new document version created if you edit a document that is under workflow.
The basic version management operations are provided by the class DocumentHelper in the methods mentioned in the previous chapter (InsertDocument, …). In order to manage the document versions, use VersionManager class methods.
Here are some examples how to work with versioned documents:
Getting the document
You always need to work with the latest document version, use DocumentHelper.GetDocument instead of just simple TreeProvider.SelectSingleNode.
[C#]
using CMS.SiteProvider; using CMS.TreeEngine; using CMS.CMSHelper; using CMS.WorkflowEngine;
// Always work with some user when editing documents UserInfo ui = UserInfoProvider.GetUserInfo("administrator"); TreeProvider tree = new TreeProvider(ui);
// First, get the base document CMS.TreeEngine.TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, "/News/Your-first-news", "en-us"); if ( node != null ) { // Get latest version of the document node = DocumentHelper.GetDocument(node, tree); } |
Checking out the document
If you edit the document, you should check it out to create a new document version and lock the document to avoid editing by someone else. Use VersionManager.CheckOut method to check out the document.
[C#]
using CMS.WorkflowEngine;
// Check out the document VersionManager vm = new VersionManager(tree); vm.CheckOut(node); |
Updating current document version
Use DocumentHelper.UpdateDocument method to update current document version.
[C#]
using CMS.WorkflowEngine;
// Update the document node.SetValue("DocumentName", "New name"); DocumentHelper.UpdateDocument(node, tree); |
Check in the document
After you edit the document, you should check it in to allow other users to edit it or allow the workflow process to continue. Use VersionManager.CheckIn to do so.
[C#]
// Check in the document vm.CheckIn(node, null, null); |
Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?updating_a_versioned_document.htm