Following code does help to find SiteInfo and site name of current or provided Sitecore item
public static SiteInfo GetSiteInfo(this Item item) { var siteInfoList = Sitecore.Configuration.Factory.GetSiteInfoList(); return siteInfoList.FirstOrDefault(info => item.Paths.FullPath.StartsWith(info.RootPath)); } public static string GetSiteName(this Item item) { var info = item.GetSiteInfo(); return info != null ? info.Name : string.Empty; }
Thanks Jignesh,
This helped me get a starting point.
Appreciate your blogpost. I edited my implementation a bit
return siteInfoList.FirstOrDefault(info => item.Paths.FullPath.StartsWith(info.RootPath + info.StartItem, StringComparison.InvariantCultureIgnoreCase));