Sunday, 15 June 2014

Remove specific language version from items in Sitecore

1 comment
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.
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!

1 comment :

  1. In mini roulette, the wheel is smaller and solely features numbers up to as} 12, as well as|in addition to} a single “0”. There’s also a further rule, which sees half a player’s wager returned if the ball lands on “0”. The croupier often starts the wheel spinning in a counterclockwise course and then spins a small ivory or plastic ball onto the bowl’s back monitor in reverse direction|the different way|the wrong way}. In roulette, you have to to|you must} anticipate the quantity or kind of pocket on which the ivory ball is going to land. 에볼루션라이트닝카지노 To do that, there are a number of bets also can make|you could make}."Inside" bets, or bets placed on particular numbers, typically have higher paying odds.

    ReplyDelete