protected Item GetDateParentNodeBasedOnLegacy(Item parentNode, string legacyPath, TemplateItem folderType) { string[] pathParts = legacyPath.Split('/').Where(p => StringService.IsInt(p) || p.StartsWith("hip", StringComparison.InvariantCultureIgnoreCase) || p.Equals("legacy", StringComparison.InvariantCultureIgnoreCase)).ToArray(); if (pathParts.Any()) { //get year folder Item year = GetChild(parentNode, pathParts[0]); if (year == null) { //build year folder if you have to year = parentNode.Add(pathParts[0], folderType); } //set the parent to year parentNode = year; } if (pathParts.Length > 1) { //get month folder Item month = GetChild(parentNode, pathParts[1]); if (month == null) { //build month folder if you have to month = parentNode.Add(pathParts[1], folderType); } //set the parent to year parentNode = month; } if (pathParts.Length > 2) { //get day folder Item day = GetChild(parentNode, pathParts[2]); if (day == null) { //build day folder if you have to day = parentNode.Add(pathParts[2], folderType); } //set the parent to year parentNode = day; } return(parentNode); }