I want to count then number of documents in a sharepoint document library in which contains about 100 thousand items. Using the code below, the exact number of documents are returned:

SPList oList = oWebsite.Lists["RSAsLibrary"];
for (int i = 0; i < oList.ItemCount; i++)
    count += 1;

but then doing a Linq to sharepoint entity query returns about 91,000 documents that's about 10,000 documents less:

List<RSAsLibraryBenefitsCT> RSASchedules = scanningsiteDB.GetList<RSAsLibraryBenefitsCT>("RSAsLibrary").Where(x => x.DocReferenceNo != null).ToList();
var RsaScheldulesDocs = from doc in RSASchedules 
                            select (doc.Name);

2 Answers 2


No need to count the list that way ItemCount.

count = oList.ItemCount;

ItemCount includes folders and files inside them. Try removing the where clause and see if the number aligns.

  • I tried removing the where clause, yet it did not work
    – Tolu Ajayi
    Commented Feb 17, 2017 at 14:36
  • Is the folder structure in your list flat? Wondering if it's conceivable the folders are not being loaded in the CSOM query. What count does the list settings page give you?
    – Thor
    Commented Feb 17, 2017 at 14:41
  • It gives the count oList.ItemCount gives and there are no folder in the library, just documents
    – Tolu Ajayi
    Commented Feb 17, 2017 at 15:30
  • Aight, just throwing out thoughts here. Do all documents have Name field?
    – Thor
    Commented Feb 17, 2017 at 15:50
  • Yes they do, Infact I checked if they were all checked in and yes they were checked in
    – Tolu Ajayi
    Commented Feb 17, 2017 at 15:54

You can try using SPListItems.

SPListItemCollection items = oList.GetItems("Name");
SPListItem item = null;
List<string> docNames = new List<string>();
foreach (SPListItem item in items)
  • Thanks for your answer Thor. Is there a way to find the date an item was created using this method. Thanks
    – Tolu Ajayi
    Commented Feb 20, 2017 at 8:30
  • DateTime created = (DateTime)item["Created_x0020_Date"]; blogs.msdn.microsoft.com/michael_yeager/2008/11/03/… helpful reference list for internal names.
    – Thor
    Commented Feb 21, 2017 at 9:35
  • If this solution solves your problem please mark it as accepted so that it can be used as reference for other searches.
    – Thor
    Commented Feb 21, 2017 at 9:37
  • Please where do I place the datetime created code. I placed it my linq to sharepoint entity file and it says item cannot be found
    – Tolu Ajayi
    Commented Feb 21, 2017 at 11:01
  • I don't understand the question. Sounds like you are in a different problem now. You are welcome to create a new question with where you are stuck and link to it here.
    – Thor
    Commented Feb 21, 2017 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.