/// <summary> /// Retrieves a recursive linked list of folders with the parent property filled in /// </summary> /// <param name="folders">Folder list from Kentico Kontent</param> /// <param name="parentLinked">Parent linked folder</param> /// <returns></returns> public static IEnumerable <AssetFolderLinkingHierarchy> GetParentLinkedFolderHierarchy(this IEnumerable <AssetFolderHierarchy> folders, AssetFolderLinkingHierarchy parentLinked = null) { // Recursively search for the folder hierarchy that an asset is in. Returns null if file is not in a folder. var folderList = new List <AssetFolderLinkingHierarchy>(); foreach (var itm in folders) { var newFolder = new AssetFolderLinkingHierarchy() { ExternalId = itm.ExternalId, Folders = (itm.Folders != null && itm.Folders.Count() > 0) ? new List <AssetFolderLinkingHierarchy>() : null, Id = itm.Id, Name = itm.Name }; if (itm.Folders != null) { newFolder.Folders = itm.Folders.GetParentLinkedFolderHierarchy(newFolder); } if (parentLinked != null) { newFolder.Parent = parentLinked; } folderList.Add(newFolder); } return(folderList); }
/// <summary> /// Gets the full folder path string /// </summary> /// <param name="folder">Folder</param> /// <returns></returns> public static string GetFullFolderPath(this AssetFolderLinkingHierarchy folder) { List <string> folderName = new List <string>(); if (folder.Parent != null) { folderName.Add(GetFullFolderPath(folder.Parent)); } folderName.Add(folder.Name); return(string.Join("\\", folderName)); }