Sunday, 25 October 2015

Get site name of Current item in Sitecore

Below code shows how to get the site name of current context item in the multi site environment of Sitecore setup

        public static string GetSiteName(this Item item)
        {
            var siteInfoList = Sitecore.Configuration.Factory.GetSiteInfoList();
            var siteInfo = siteInfoList.FirstOrDefault(
                info => item.Paths.FullPath.ToLower().StartsWith(info.RootPath.ToLower()));

            return siteInfo.Name;
        }

No comments:

Post a Comment