title: How do I get folder size with Exchange Web Services 2010 Managed API?
body: <p>I'm attempting to use EWS 2010 Managed API to get the total size of a user's mailbox. I haven't found a web service method to get this data, so I figured I would try to calculate it. I found one seemingly-applicable question on another site about <a href="http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/31f9a157-4d19-44bf-ad58-62577915b624/" rel="noreferrer">finding mailbox sizes with EWS 2007</a>, but either I'm not understanding what it's asking me to do, or that method just doesn't work with EWS 2010.</p>
  
  <p>Noodling around in the code insight, I was able to write what I thought was a method that would traverse the folder structure recursively and result in a combined total for all folders inside the Inbox:</p>
  
  <pre><code>private int traverseChildFoldersForSize(Folder f)
  {
      int folderSizeSum = 0;
      if (f.ChildFolderCount &gt; 0)
      {
          foreach (Folder c in f.FindFolders(new FolderView(10000)))
          {
              folderSizeSum += traverseChildFoldersForSize(c);
          }
      }
  
      folderSizeSum += (int)f.ManagedFolderInformation.FolderSize;
  
      return folderSizeSum;
  }
  </code></pre>
  
  <p>(Assumes there aren't more than 10,000 folders inside a given folder. Figure that's a safe bet...)</p>
  
  <p>Unfortunately, this doesn't work.</p>
  
  <p>I'm initiating the recursion with this code:</p>
  
  <pre><code>Folder root = Folder.Bind(svc, WellKnownFolderName.Inbox);
  int totalSize = traverseChildFoldersForSize(root);
  </code></pre>
  
  <p>But a Null Reference Exception is thrown, essentially saying that <code>[folder].ManagedFolderInformation</code> is a null object reference.</p>
  
  <p>For clarity, I also attempted to just get the size of the root folder:</p>
  
  <pre><code>Console.Write(root.ManagedFolderInformation.FolderSize.ToString());
  </code></pre>
  
  <p>Which threw the same NRE exception, so I know that it's not just that once you get to a certain depth in the directory tree that ManagedFolderInformation doesn't exist.</p>
  
  <p>Any ideas on how to get the total size of the user's mailbox? Am I barking up the wrong tree?</p>