ContentLink ChildItem Sorting
I has a code below which retrieve from database. The data has a chidItem. I need to sort the child item before it assign to the other variable. Anyone has idea how I can make it? Please help!
ContentLink[] contentLink = (ContentLink[])channelScheduleManagement.GetValue("DownloadableFiles");
scheduleExcelTitle = new string[contentLink.Length];
scheduleExcelURL = new string[contentLink.Length];
for (int c = 0; c < contentLink.Length; c++)
var doc = libraryManager.GetDocument(contentLink[c].ChildItemId);
scheduleExcelTitle[c] = doc.Title;
scheduleExcelURL[c] = doc.Url;
Hi Derick,
I created some code for you to check out. This is what it does:
Be aware that when you sort Documents by Title you need to use the Title.Value property, since the Title property is of type LString, which is a Sitefinity specific string used for multilingual purposes.
If you want the Title to be sorted for a specific Culture, you need to use the method GetString on the Title property.
/// <summary> /// Get Press Releases /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void cmdGet_OnClick(object sender, EventArgs e) var results = GetDocumentsFromPressRelease("Press Release 1"); /// <summary> /// Get Documents from a Press Release item /// </summary> /// <param name="title"></param> /// <returns></returns> private Dictionary<string, string> GetDocumentsFromPressRelease(string title) // Get the DynamicModule manager var dynamicModuleManager = DynamicModuleManager.GetManager(); var pressReleaseType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Pressreleases.PressRelease"); // Get a collection with Press Releases var pressRelease = dynamicModuleManager.GetDataItems(pressReleaseType).Where(x => x.Status == ContentLifecycleStatus.Live && x.Visible && x.GetValue<string>("Title") == title).OrderBy(x => x.GetValue<string>("Title")).FirstOrDefault(); if (pressRelease == null) return null; // Get Documents from the Press Release var documents = pressRelease.GetValue<ContentLink[]>("Documents"); // Define result Dictionary var results = documents.Select(item => GetDocument(item.ChildItemId)) .Where(document => document != null).OrderByDescending(x => x.Title.Value) .ToDictionary<Document, string, string>(document => document.Title, document => document.MediaUrl); return results; /// <summary> /// Get a Document from the Libraries /// </summary> /// <param name="documentId"></param> /// <returns></returns> private Document GetDocument(Guid documentId) var manager = LibrariesManager.GetManager(); return (documentId != Guid.Empty) ? manager.GetDocument(documentId) : null; Hi,
Thank you Danie for sharing this solution. I hope that Derick will find it useful.
Regards,
Stefani Tacheva
Telerik