How to delete all item version besides default language?

730 Views Asked by At

For some reason sitecore has created multi-versions in all languages. Is there way to delete all the version and the languages besides default language through Site core Rocks Query?

Thanks

2

There are 2 best solutions below

0
Helga On

You can delete the language item from the system/Languages and it will remove this language version from all the items automatically.

0
Jitendra soni On

You can remove this language from the system and it will take care this item, then publish the site - this will resolve this issue.

If you still have any issue - Please remove this explicitly, Below is the sample code

I have used this code to add version for all languages, May be this help to remove explicitly.

var homeItemA = Sitecore.Context.Database.GetItem(Landings.HomeItem); var languageA = Sitecore.Globalization.Language.Parse("en-SG");//new language version

        var master = Sitecore.Configuration.Factory.GetDatabase("master");

        var allItems = master.GetItem(homeItemA.Paths.FullPath).Axes.GetDescendants();



        foreach (var blog in allItems)
        {
            Item ca = master.GetItem(blog.Paths.FullPath, languageA);


            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                try
                {
                    if (0 == ca.Versions.Count)
                    {
                        ca.Versions.AddVersion();
                    }


                }
                catch (Exception ex)
                {
                    ca.Editing.CancelEdit();

                }
            }
        }

See my own blog for more details