Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 639235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:49:12+00:00 2026-05-13T20:49:12+00:00

Right now all I am using to calculate the size are the files in

  • 0

Right now all I am using to calculate the size are the files in the folders. I do not think this is all of it, because the content database size is about 15gb. When I calculate the size of all the files I get around 10gb. Does anyone know what I may be missing?

Here is the code I have so far.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Globalization;

namespace WebSizeTesting
{
class Program
{


    static void Main(string[] args)
    {
        long SiteCollectionBytes = 0;

        using (SPSite mainSite = new SPSite("http://sharepoint-test"))
        {
            // loop through the websites
            foreach (SPWeb web in mainSite.AllWebs)
            {

                long webBytes = GetSPFolderSize(web.RootFolder);

                // Add in size of each web site's recycle bin

                webBytes += web.RecycleBin.OfType<SPRecycleBinItem>().Select(item => item.Size).ToArray<long>().Sum();

                Console.WriteLine("Url: {0}, Size: {1}", web.Url, ConvertBytesToDisplayText( webBytes ));

                SiteCollectionBytes += webBytes;
            }


            long siteCollectionRecycleBinBytes = mainSite.RecycleBin.OfType<SPRecycleBinItem>().Select(item => item.Size).ToArray<long>().Sum();

            Console.WriteLine("Site Collection Recycle Bin: " + ConvertBytesToDisplayText(siteCollectionRecycleBinBytes));

            SiteCollectionBytes += siteCollectionRecycleBinBytes;
        }

        Console.WriteLine("Total Size: " + ConvertBytesToDisplayText(SiteCollectionBytes));

        Console.ReadKey();
    }



    public static long GetSPFolderSize(SPFolder folder)
    {
        long byteCount = 0;

        // calculate the files in the immediate folder
        foreach (SPFile file in folder.Files)
        {
            byteCount += file.TotalLength;

            // also include file versions
            foreach (SPFileVersion fileVersion in file.Versions)
            {
                byteCount += fileVersion.Size;
            }

        }

        // Handle sub folders
        foreach (SPFolder subFolder in folder.SubFolders)
        {
            byteCount += GetSPFolderSize(subFolder);
        }

        return byteCount;
    }

    public static string ConvertBytesToDisplayText(long byteCount)
    {
        string result = "";

        if (byteCount > Math.Pow(1024, 3))
        {
            // display as gb
            result = (byteCount / Math.Pow(1024, 3)).ToString("#,#.##", CultureInfo.InvariantCulture) + " GB";
        }
        else if (byteCount > Math.Pow(1024, 2))
        {
            // display as mb
            result = (byteCount / Math.Pow(1024, 2)).ToString("#,#.##", CultureInfo.InvariantCulture) + " MB";
        }
        else if (byteCount > 1024)
        {
            // display as kb
            result = (byteCount / 1024).ToString("#,#.##", CultureInfo.InvariantCulture) + " KB";
        }
        else
        {
            // display as bytes
            result = byteCount.ToString("#,#.##", CultureInfo.InvariantCulture) + " Bytes";
        }

        return result;
    }
}
}

edit 2:15 pm 3/1/2010 cst I added in the ability to count file versions as part of the size to the code. As was suggested by Goyuix in the post below. It still is off by a considerable amount of the physical database size.

edit 8:38 am 3/3/2010 cst I added in the calculating of the recycle bin size for each web, and the site collection recycle bin. These changes where suggested by ArjanP. Also i wanted to add, that I am very open to more efficient ways of doing this.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:49:12+00:00Added an answer on May 13, 2026 at 8:49 pm

    Did you consider the Trash Can? There will be cans for Webs and the Site Collection, all taking up space in the content database.

    There will always be ‘overhead’ in a content database.. every ’empty’ Web will consume a number of bytes already. 30% seems much but not excessive, it depends on the ratio of content and the number of webs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I'm not sure if I'm going about all this the right way.
Setting up the sandboxes for all these option is not feasible right now. So
I'm using Rails 3, Uploadify, to send images to S3. Right now all the
I have a medium-size Java Web-application using Log4J as logging-framework. Right now i am
Right now all of my times on my reports are in GMT. Anybody know
I'm developing a facebook app right now all by my lonesome. I'm attempting to
Right now we have AD/Exchange to manage all of our users logins/e-mail on-site at
right now i am simply ftping everything (all of my source code included) but
Right now, I have all the employees of my company login to an external
I installed all the necessary packages for running GUI programs in Cygwin. Right now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.