|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
|
Please note
For these examples to produce meaningful results, it is expected to run the API examples on the Creating documents page first.
|
The following example gets all documents located under a folder in the content tree and updates them.
private bool GetAndUpdateDocuments() { // Create an instance of the Tree provider first TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Fill dataset with documents DataSet documents = tree.SelectNodes(CMSContext.CurrentSiteName, "/API-Example/%", "en-us", false, "CMS.MenuItem");
if (!DataHelper.DataSourceIsEmpty(documents)) { // Loop through all documents foreach (DataRow documentRow in documents.Tables[0].Rows) { // Create a new Tree node from the data row TreeNode editDocument = TreeNode.New(documentRow, "CMS.MenuItem", tree);
string newName = editDocument.DocumentName.ToLower();
// Change coupled data editDocument.SetValue("MenuItemName", newName); // Change document data editDocument.DocumentName = newName;
// Save to database editDocument.Update();
return true; } }
return false; } |
The following example creates a copy of a document.
private bool CopyDocument() { // Create an instance of the Tree provider first TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example/My-new-document", "en-us");
// Get the new parent document TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example/Source", "en-us");
if ((node != null) && (parentNode != null)) { // Copy the document tree.CopyNode(node, parentNode.NodeID);
return true; }
return false; } |
The following example moves a document.
private bool MoveDocument() { // Create an instance of the Tree provider first TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example/Source/My-new-document", "en-us");
// Get the new parent document TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example/Target", "en-us");
if ((node != null) && (parentNode != null)) { // Move the document tree.MoveNode(node, parentNode.NodeID);
return true; }
return false; } |