Create a version of an item in a language

Current version: 9.2

You can create a version of an item in a language by using the Sitecore.Data.Items.Versions.Add method. For example, to add the first version to the /Sitecore/Content/Home item in the Master database for each language for which version data does not already exist:

Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home");

foreach (Sitecore.Globalization.Language language in home.Languages)
    Sitecore.Data.Items.Item langItem = home.Database.GetItem(home.ID, language);

    if (langItem.Versions.Count < 1)
        langItem = langItem.Versions.AddVersion();

Do you have some feedback for us?

If you have suggestions for improving this article,