Kentico CMS 6.0 Developer's Guide

Object recycle bin

Object recycle bin

Previous topic Next topic Mail us feedback on this topic!  

Object 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 deletes the CSS stylesheet created on the previous page and moves it to the objects recycle bin.

 

private bool DeleteObject()

{

  // Get the css stylesheet

   CssStylesheetInfo deleteStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

 

  if (deleteStylesheet != null)

   {

      // Check if restoring from recycle bin is allowed on current site

      if (ObjectVersionManager.AllowObjectRestore(deleteStylesheet, CMSContext.CurrentSiteName))

       {

          // Delete the css stylesheet

           CssStylesheetInfoProvider.DeleteCssStylesheetInfo(deleteStylesheet);

 

          return true;

       }

   }

 

  return false;

}

 

The following example restores the CSS stylesheet deleted by the example above from the objects recycle bin back to the administration interface.

 

private bool RestoreObject()

{

  // Prepare query parameters

  string where = "VersionObjectType = '" + SiteObjectType.CSSSTYLESHEET + "' AND VersionDeletedByUserID = " + CMSContext.CurrentUser.UserID;

  string orderBy = "VersionDeletedWhen DESC";

  int topN = 1;

 

  // Get dataset with versions according to the parameters

   DataSet versionDS = ObjectVersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, null);

 

  if (!DataHelper.DataSourceIsEmpty(versionDS))

   {

      // Get version

       ObjectVersionHistoryInfo version = new ObjectVersionHistoryInfo(versionDS.Tables[0].Rows[0]);

 

      // Restore the object

       ObjectVersionManager.RestoreObject(version.VersionID, true);

 

      return true;

   }

 

  return false;

}

 

The following example deletes the CSS stylesheet permanently without moving it to the object recycle bin.

 

private bool DestroyObject()

{

  // Get the css stylesheet

   CssStylesheetInfo destroyStylesheet = CssStylesheetInfoProvider.GetCssStylesheetInfo("MyNewVersionedStylesheet");

 

  if (destroyStylesheet != null)

   {

      // Destroy the object (in action context with disabled creating of new versions for recycle bin)

      using (CMSActionContext context = new CMSActionContext())

       {

          // Disable creating of new versions

           context.CreateVersion = false;

 

          // Destroy the css stylesheet

           CssStylesheetInfoProvider.DeleteCssStylesheetInfo(destroyStylesheet);

 

          return true;

       }

   }

 

  return false;

}