Getting documents from a specific library

Posted by Community Admin on 03-Aug-2018 10:50

Getting documents from a specific library

All Replies

Posted by Community Admin on 24-May-2011 00:00

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

Posted by Community Admin on 26-May-2011 00:00

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

This thread is closed