Sitecore 5.0 API

Version Structure

Represents a version number of an item.

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

System.Object
   System.ValueType
      Sitecore.Data.Version

[Visual Basic]
Public Structure Version
    Implements ISerializable
[C#]
public struct Version : ISerializable

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.

The number of the version is stored in the Number property which is an integer.

The string representation of a version can be retrieved using the ToString method. A string can be converted to a version number using the Parse method.

The Latest static property represents the latest version. This is the version number zero (0). The latest version is usually the default version. The First static property represent the first version, that is the number one (1) version. In some cases an invalid version is returned. The invalid version is represented by the Invalid version, which has number minus one (-1).

The name of the version is a unused at the time, but reserved for future use.

Example

This example gets an item in a database.

public Item GetItem(string databaseName, string id, string language, string version) {
  ID itemID = ID.Parse(id);

  Language itemLanguage = Language.Parse(language);
  
  Sitecore.Data.Version itemVersion = Sitecore.Data.Version.Parse(version);

  Database database = Factory.GetDatabase(databaseName);

  if (database != null) {
    return database.Items[itemID, itemLanguage, itemVersion];
  }

  return null;
}

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

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

See Also

Version Members | Sitecore.Data Namespace