Try Now
More in this section

Forums / Developing with Sitefinity / ContentLink ChildItem Sorting

ContentLink ChildItem Sorting

3 posts, 0 answered
  1. Derick
    Derick avatar
    6 posts
    13 Jul 2013
    23 Jul 2013
    Link to this post
    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;                    
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    18 Feb 2004
    23 Jul 2013 in reply to Derick
    Link to this post
    Hi Derick,

    I created some code for you to check out. This is what it does:

    1. Gets a single Press Release item
    2. Get the Documents from the Press Release item
    3. Orders the results by Title descending
    4. Adds the Title and MediaUrl to a Dictionary<string, string>

    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;

    Kind regards,

  3. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    19 Oct 2016
    25 Jul 2013
    Link to this post

    Thank you Danie for sharing this solution. I hope that Derick will find it useful.

    Stefani Tacheva
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
3 posts, 0 answered