Blog about Microsoft technologies, Office System, SharePoint, MOSS, WSS, Search and "The new world of work"
in

Size of SPWeb based on its Folders and Files

 I was looking through some old code I wrote for customers and found this code again. It is used for determining the size of a SPWeb object based on its files. The methods are recursively through all SPWeb, SPFolder and SPFile objects. The result is the size of the SPWeb in number of bytes.

private long GetWebSize(SPWeb web)
{
    long total = 0;

    foreach (SPFolder folder in web.Folders)
    {
        total += GetFolderSize(folder);
    }

    foreach (SPWeb subweb in web.Webs)
    {
        total += GetWebSize(subweb);
        subweb.Dispose();
    }

    return total;
}

private long GetFolderSize(SPFolder folder)
{
    long folderSize = 0;

    foreach (SPFile file in folder.Files)
    {
        folderSize += file.Length;
    }

    foreach (SPFolder subfolder in folder.SubFolders)
    {
        folderSize += GetFolderSize(subfolder);
    }

    return folderSize;
}

I have seen in the past that some people even write methods to access the content databases of SharePoint itself. But keep in mind that Microsoft will not garantee that these content databases stay the same between Service Packs en versions of SharePoint. Neither will they provide help in any way when code like that is found in projects. So keep it to the API functionality which is available to us.

» Trackbacks & Pingbacks

  1. Aunque cada vez es más difícil ponerse al día, sobre todo por la falta de tiempo, de vez en cuando consigo

    Blog del CIIN — May 4, 2008 8:35 PM
  2. Pingback from  WSS 3.0 & MOSS: Recopilación de enlaces interesantes (XVII)! « Pasi??n por la tecnolog??a…

  3. As most of you all know you need to prevent your content databases to expand too much. According to best

    Alex blog about Microsoft — May 29, 2008 12:57 PM
Trackback url for this post:
http://www.bloggix.com/blogs/microsoft/trackback.ashx?PostID=247

» Comments

    No comments yet. Be the first to comment!

» Leave a Comment

(required) 
(optional)
(required) 

Submit

Subscriptions

News

SlideShare.net
I'm using SlideShare.net for sharing my presentation material. You can find it here

Dutch SharePoint User Group
The Dutch SharePoint User Group is an independent social network for people to collaborate and share information around SharePoint Technology and products. By learning from others you can improve your skills and expertise, around areas, which are then again a benefit to the social network. This platform is a community platform for SharePoint developers, architects and designer who want to share information, tricks, code and content. Its also a good starting point for people without SharePoint knowledge who are interested in SharePoint Technology. Read more

Oktober 2008 i'm working for a new company called Sparked. The new world of work causes organizations to re-think about their ways of communication and interaction with their customers.

Increasing usage of web technology and the new generation workers brings changes into these organizations.

Sparked helps these organizations to accelerate adoption of this technology platform to effectively use it around content management, content exposure and collaboration.


April 2008 i have been to the first SharePoint Conference in Dubai. Dubai is an overwhelming town with a lot of passionate people. I had a great time. Thank you my friends!



You can also find my on Facebook

Tags

Alexander Meijers

Previous Blog about SharePoint