Kentico CMS 7.0 Developer's Guide

Recycle bin

Recycle bin

Previous topic Next topic Mail us feedback on this topic!  

Recycle bin

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example moves Document 1 created by the code example in the Sample document structure topic the recycle bin.

 

private bool MoveToRecycleBin()

{

  // Create an instance of the Tree provider

  TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

 

  // Get the document

  TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example/Document-1", "en-us");

 

  if (node != null)

   {

      // Delete the document without destroying its history

      DocumentHelper.DeleteDocument(node, tree, true, false, true);

 

      return true;

   }

 

  return false;

}

 

The following example restores the document moved to the recycle bin by the example above back to the content tree.

 

private bool RestoreFromRecycleBin()

{

  // Prepare the where condition

  string where = "VersionNodeAliasPath LIKE N'/API-Example/Document-1'";

 

  // Get the recycled document

  DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin(CMSContext.CurrentSiteID, where, null, 0, "VersionHistoryID");

 

  if (!DataHelper.DataSourceIsEmpty(recycleBin))

   {

      // Create a new version history info object from the data row

      VersionHistoryInfo version = new VersionHistoryInfo(recycleBin.Tables[0].Rows[0]);

 

      // Create a new version manager instance and restore the document

      VersionManager manager = VersionManager.GetInstance(new TreeProvider(CMSContext.CurrentUser));

       manager.RestoreDocument(version.VersionHistoryID);

 

      return true;

   }

 

  return false;

}