Namespace: ITHit.WebDAV.Server.DeltaV
[Missing <param name="version"/> documentation for "M:ITHit.WebDAV.Server.DeltaV.IVersionableItem.UpdateToVersion(ITHit.WebDAV.Server.DeltaV.IVersion)"]
Exception | Condition |
---|---|
LockedException | This item was locked. Client did not provide the lock token. |
NeedPrivilegesException | The user doesn't have enough privileges. |
InsufficientStorageException | Quota limit is reached. |
MultistatusException | Errors has occurred during processing of the subtree. |
DavException | In other cases. |
In your UpdateToVersion(IVersion) implementation you will create a new version and copy content and properties from IVersion passed as a parameter to new version. You will also replace content and properties of this item. The new created version becomes current version.
The UpdateToVersion(IVersion) method can only be called when item is in check-in state.
The code below is part of 'WebDAVServer.DeltaV' sample provided with the SDK.
public void UpdateToVersion(IVersion version) { RequireHasToken(); // Create a new version and copy content and properties from IVersion passed as a parameter. // Replace content and properties of this item. Version ver = version as Version; if (ver.ItemId != this.ItemId) { throw new DavException("The version must be from the same item.", DavStatus.CONFLICT); } IVersion v = this.VersionHistory.GetCurrentVersion(); Version currVersion = v as Version; int newVersionNumber = currVersion.VersionNumber + 1; Guid newID = Guid.NewGuid(); string command = @"INSERT INTO Version( ItemId, VersionId, VersionNumber, Name, Comment, CreatorDisplayName, Content, ContentType, Created, SerialNumber) SELECT @ItemId, @Identity, @VersionNumber, i.Name, i.Comment, i.CreatorDisplayName, v.Content, i.ContentType, GETUTCDATE(), v.SerialNumber FROM Item i INNER JOIN [Version] v ON v.ItemId = i.ItemId WHERE i.ItemId = @ItemId AND v.VersionId = @VersionId"; Context.ExecuteNonQuery( command, "@ItemId", ItemId, "@VersionNumber", newVersionNumber, "@Identity", newID, "@VersionID", ver.VersionId); string updateContentCommand = @"UPDATE Item SET Content = v.Content, SerialNumber = v.SerialNumber FROM Item i INNER JOIN [Version] v ON i.ItemId = v.ItemId WHERE i.ItemId = @ItemId AND v.VersionId = @versionID"; Context.ExecuteNonQuery( updateContentCommand, "@ItemId", ItemId, "@VersionId", ver.VersionId); // Copy properties to this item Context.ExecuteNonQuery( "DELETE FROM Property WHERE ItemID = @ItemID", "@ItemId", ItemId); string insertPropertyCommand = @"INSERT INTO Property(ItemId, Name, Namespace, PropVal) SELECT @ItemId, Name, Namespace, PropVal FROM VersionProperty WHERE VersionId = @VersionId"; Context.ExecuteNonQuery( insertPropertyCommand, "@ItemId", ItemId, "@VersionId", ver.VersionId); string insertVersionPropertyCommand = @"INSERT INTO VersionProperty(VersionId, Name, Namespace, PropVal) SELECT @NewVerId, Name, Namespace, PropVal FROM VersionProperty WHERE VersionId = @VersionId"; Context.ExecuteNonQuery( insertVersionPropertyCommand, "@NewVerId", newID, "@VersionId", ver.VersionId); }