/// <summary> /// Restore a specific file version as the current version. /// </summary> /// <param name="versioningFileItem">A versioning file instance containing the version to restore.</param> /// <param name="versionId">Version id of the version to restore.</param> public static void RestoreVersion(IVersioningFile versioningFileItem, string versionId) { Validate.RequiredParameter("versioningFileItem", versioningFileItem); if (String.IsNullOrEmpty(versionId)) { throw new ArgumentException("versionId can not be null or empty", "versionId"); } ThrowIfCheckedOut(versioningFileItem); IList <UnifiedVersion> versions = versioningFileItem.GetVersions(); if (versions.Count == 1) { throw new InvalidVersioningOperationException("Can not restore version when only one version exists."); } UnifiedVersion targetVersion = versions.SingleOrDefault <UnifiedVersion>(v => v.Id.ToString() == versionId); if (targetVersion == null) { throw new VersionNotFoundException(versionId); } var query = from version in versions orderby version.Changed descending select version; UnifiedVersion lastVersion = query.First <UnifiedVersion>(); if (lastVersion.Id.ToString() == targetVersion.Id.ToString()) { throw new InvalidVersioningOperationException("The version to be restored is already the currently active version."); } targetVersion.Restore(); }