Sitecore 5.0 API

ItemVersions Class

Provides methods for working with versions of an item.

For a list of all members of this type, see ItemVersions Members.

System.Object
   Sitecore.Data.Items.ItemVersions

[Visual Basic]
Public Class ItemVersions
[C#]
public class ItemVersions

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

An item may have multiple versions within a language. Only one version is published at a time and therefore viewable on the website. A version is identified by an integer number.

Other versions of the item can be retrieved using the Item property.

The version numbers of this item in this language can be obtained using the GetVersionNumbers methods. This returns an array of integers that represents the version numbers. To get the actual items use the GetVersions method.

A new version of the item, can be created with the AddVersion method. The new version will have the the same field values as the latest version. The version number will be one higher than the latest version.

A version can be deleted with the RemoveVersion method. To delete all the versions within a language use the RemoveAll methods.

Example

The following example builds a listview control containing icons for each version of an item.

public void DisplayVersions(Control parent, Item item) {
  foreach (Item version in item.Versions.GetVersions()) {
    ListviewItem listviewItem = new ListviewItem();

    Sitecore.Context.ClientPage.AddControl(parent, listviewItem);

    listviewItem.ID = "Version" + version.Version.Number.ToString();
    listviewItem.Header = version.Version.Number.ToString();
    listviewItem.Icon = version.Appearance.Icon;
  }
}

Requirements

Namespace: Sitecore.Data.Items

Assembly: Sitecore.Kernel (in Sitecore.Kernel.dll)

See Also

ItemVersions Members | Sitecore.Data.Items Namespace