Get size of a document library


  • Hi all,

    I need to show the total size of a document library. How can I retrive this information programmatically?

    Tuesday, February 17, 2009 12:30 PM


All replies

  • Hi,

    you can enumerate all SPFile objects, and for each file you can get SPFileVersion object which has Size property.

    Sasa Tomicic <--> MCTS WSS 3.0, MCPD EAD...
    Tuesday, February 17, 2009 12:47 PM
  • Hi Sasa,

    Thanks for your reply. Whatever way you have specified, that will cause a huge loop iteration to get the total size while document library is having huge number of files and sub folders.

    Is sharepoint is maintaing this size information in some place from where we can retrive this directly?
    Tuesday, February 17, 2009 1:25 PM
  • Srishendu,
        You can query from sharepoint database directly which is not a recommended practice. Lots of samples are given in this Code Project Article (for SPS 2003) and the last query may be of interest to you.

    Otherwise, You can store the size of the documents (one time action of looping through all the documents) in a separate sharepoint list or a file in the server hard drive and update it whenever a new item is added.

    I can find SPSite.UsageInfo structure which retrieves storage for discussions and site but not list usage.
    Tuesday, February 17, 2009 4:34 PM
  • Sirshendu,

    As stated by Sasa, you do need to do recursion to get this sort of information. There is no one-stop shop to get this information.
    Blog; --- Posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 17, 2009 4:45 PM
  • I do think you can get this info from database.
    It's simple and seems no hurt to sharepoint.
    Wednesday, February 18, 2009 6:19 AM
  • "Directly querying or modifying the database can place extra load on a server, or can expose information to users in a way that violates security policies or personal information management policies. If server-side code must query data, then the process for acquiring that data should be through the built-in SharePoint object model, and not by using any type of query to the database. Client-side code that must modify or query data in SharePoint Products and Technologies can do this by using calls to the built-in SharePoint Web services that in turn call the object model"
    Blog; --- Posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, February 18, 2009 10:15 AM
  • Don't query the database, schemas are likely to change and MS don't support this ... please use the API.

    Have you looked at SPSite.StorageManagementInformation method?  It takes in 3 parameters and returns a data table.  You can supply StorageManagementInformationType.DocumentLibrary and use the .Select method of the DataTable to retrieve the document library you are interested in.

    Here's a few links:



    Hope this helps

    My SharePoint Blog -
    • Marked as answer by Mike Walsh FIN Wednesday, February 18, 2009 11:15 AM
    Wednesday, February 18, 2009 10:57 AM