Click or drag to resize

IVersionableItemUpdateToVersion Method

IT Hit WebDAV Classes Reference
Updates content and properties of the item to those identified by version parameter.

Namespace: ITHit.WebDAV.Server.DeltaV
Assembly: ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 4.5.3121.0
Syntax
void UpdateToVersion(
	IVersion version
)

Parameters

version
Type: ITHit.WebDAV.Server.DeltaVIVersion

[Missing <param name="version"/> documentation for "M:ITHit.WebDAV.Server.DeltaV.IVersionableItem.UpdateToVersion(ITHit.WebDAV.Server.DeltaV.IVersion)"]

Return Value

Type: 
.
Exceptions
ExceptionCondition
LockedExceptionThis item was locked. Client did not provide the lock token.
NeedPrivilegesExceptionThe user doesn't have enough privileges.
InsufficientStorageExceptionQuota limit is reached.
MultistatusExceptionErrors has occurred during processing of the subtree.
DavExceptionIn other cases.
Remarks

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.

Examples

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);
}
See Also