In this blog post; I am going to explain how to remove a specific language version from items in Sitecore programmatically. Currently; I have got into a situation where I have to remove a specific language version (fr-FR in my case) from Sitecore items of a multilingual website. Below function RemoveLanguageVersion(string rootItemPath, string languageName) takes the root item path and language name  as input parameter and remove given language version from root item and child items of root item.
Comments and suggestions are most welcome. Happy coding!
public void RemoveLanguageVersion(string rootItemPath, string languageName)
        {
            Language languageRemove = Sitecore.Globalization.Language.Parse(languageName);
            Item rootItem = Sitecore.Context.Database.GetItem(rootItemPath, languageRemove);
            if (rootItem != null)
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    //Remove language version from root item               
                    rootItem.Versions.RemoveVersion();
                    //Remove language version recursively from child items of root item
                    foreach (Item child in rootItem.Axes.GetDescendants().Where(l => l.Language == languageRemove))
                    {
                        child.Versions.RemoveVersion();
                    }
                }
            }
        }
Example:
string rootItemPath = "/sitecore/content/Home/Audience"; string languageName = "fr-FR"; RemoveLanguageVersion(rootItemPath, languageName);Above code will remove fr-FR language version from item /sitecore/content/Home/Audience and its child item recursively.
Comments and suggestions are most welcome. Happy coding!
 
 
 
 
 
 
 
 Posts
Posts
 
 
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
B26KA8
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
BCMBS
8912195B21
ReplyDeleteinsta takipçi satın al
black swivel accent chair