More in this section

Forums / General Discussions / Getting documents from a specific library

Getting documents from a specific library

2 posts, 0 answered
  1. F
    F avatar
    34 posts
    Registered:
    15 Mar 2011
    24 May 2011
    Link to this post
    Hello,

    I had difficulties getting documets from a library i called "JobApplications", so I debugged step by step the following code :

    string title;
                int i;
                int iCount;
                  
                App.WorkWith().DocumentLibraries().ForEach(lib =>
                {
                    title = lib.Title;
                    i = lib.Items.Count;
                });
      
                App.WorkWith()
                          .Documents()
                          .Where(item => item.Parent.Title == "JobApplications" && item.Status == ContentLifecycleStatus.Live)
                          .OrderByDescending(item => item.DateCreated)
                          .Count(out iCount);

    By going step by step in the first part of the code, I checked that a library with the Title "JobApplications" existed, and had 4 items in it (the part starting with "App.WorkWith().DocumentLibraries().ForEach(lib => ...").

    Then, in the second part (starting with "App.WorkWith().Documents().Where(...)), I try to look for documents which belong to the library named "JobApplications", and count them.
    I find 0 documents, while the first part counted 4...

    Is there something i did wrong? Am I counting the documents i thought?

    Thank you,
    F
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    26 May 2011
    Link to this post
    Hello F,

    You can try getting the library by its title, and then you can directly access the stored documents in that library. Please note you'll also need to filter for the Draft states of the documents. I've provided a small code sample that's getting all the documents with Live state from my Default Library, please take a look at it, hope it helps you achieve the desired functionality.

    var library = App.WorkWith().DocumentLibraries().Where(lib => lib.Title == "Default Library").Get().First();
    var documents = library.Documents.Where(d => d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).ToList();


    All the best,
    Boyan Barnev
    the Telerik team
    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
2 posts, 0 answered