1

I have to delete the language version of a Sitecore item. For Ex. if it has 5 numbered versions in the English language so I have to delete all 5 at once.

I have tried by item.Versions.RemoveVersion(); but it deletes only one numbered version. Is there any other method available for this?

1
  • 1
    Have you tried item.Versions.RemoveAll()? Commented Mar 7, 2023 at 13:39

1 Answer 1

6

You can use item.Versions.RemoveAll() method.

Language languageRemove = Sitecore.Globalization.Language.Parse(languageCode);
Item rootItem = db.GetItem(rootItemPath, languageRemove);
if (rootItem != null)
{
    using (new Sitecore.SecurityModel.SecurityDisabler())
    {
        //Remove all the versions from item
        rootItem.Versions.RemoveAll(false);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.