/// <summary> /// Deletes a specified document version. Called when the "Delete version" button is pressed. /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first. /// </summary> private bool DeleteVersion() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Prepare parameters string siteName = CMSContext.CurrentSiteName; string aliasPath = "/API-Example"; string culture = "en-us"; bool combineWithDefaultCulture = false; string classNames = TreeProvider.ALL_CLASSNAMES; string where = null; string orderBy = null; int maxRelativeLevel = -1; bool selectOnlyPublished = false; string columns = null; // Get the document TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree); if (node != null) { // Prepare the WHERE condition for the latest document version where = "DocumentID = " + node.DocumentID; orderBy = "ModifiedWhen DESC"; int topN = 1; // Get the version ID DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(versionHistory)) { // Create the Version history info object VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]); VersionManager versionManager = VersionManager.GetInstance(tree); // Delete the version versionManager.DestroyDocumentVersion(version.VersionHistoryID); return(true); } else { apiDeleteVersion.ErrorMessage = "The document's version history is empty."; } } return(false); }
//Reverting to published version if i am editing a published document and then go for edit it. //But i have not changed any thing and click on cancel button. //Document should shown as published again //It was showing as draft because its creating a new version.So added code here for showing that document as published. public static bool RollbackToPreviousVersion(int NodeID) { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); // Prepare parameters string siteName = SiteContext.CurrentSiteName; string culture = "en-us"; string where = null; string orderBy = null; string columns = null; // Get the document TreeNode node = DocumentHelper.GetDocument(NodeID, culture, tree); if (node != null) { // Prepare the WHERE condition for the oldest document version where = "DocumentID = " + node.DocumentID; orderBy = "ModifiedWhen DESC"; int topN = 2; // Get the version ID DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns); if (!DataHelper.DataSourceIsEmpty(versionHistory) && node.IsPublished == true) { // Create the Version history info object //get the details of previous version of this document VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]); VersionManager versionManager = VersionManager.GetInstance(tree); //get the workflow stepid of previous version of this document int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID); //move that document to previous version workflow state MoveToWorkflowStep(WorkFlowStepID, tree, node); } else if (!DataHelper.DataSourceIsEmpty(versionHistory) && versionHistory.Tables[0].Rows.Count > 1) { // Create the Version history info object //get the details of previous version of this document VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]); VersionManager versionManager = VersionManager.GetInstance(tree); //get the workflow stepid of previous version of this document int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID); //move that document to previous version workflow state MoveToWorkflowStep(WorkFlowStepID, tree, node); } } return(true); }