title: How does one get the inbox folder and item count?
body: <p>I finally managed to work out how to create item counts of the inbox, sent items, calendar &amp; contacts but I'm having problems with the folder count. </p>
  
  <p>Let say I have 5 folders created in my mailbox and 2 sub folders in each folder. When I run this code, it counts 5 folders instead of all folders and sub folders which would equal 15 folder.</p>
  
  <p>I'm guessing a foreach statement or something but I still a newb :-)</p>
  
  <pre><code>#region Run Item Count
  
  Microsoft.Office.Interop.Outlook.Application app = null;
  Microsoft.Office.Interop.Outlook._NameSpace ns = null;
  
  private void btnRunItemCount_Click(object sender, EventArgs e)
  {
      app = new Microsoft.Office.Interop.Outlook.Application();
      ns = app.GetNamespace("MAPI");
  
      MAPIFolder oInbox = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
      tbInboxItemCount.Text = oInbox.Items.Count.ToString();
      MAPIFolder oSentItems = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
      tbSentMailItemCount.Text = oSentItems.Items.Count.ToString();
      MAPIFolder oCalendar = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
      tbCalendarItemCount.Text = oCalendar.Items.Count.ToString();
      MAPIFolder oContacts = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
      tbContactsItemCount.Text = oContacts.Items.Count.ToString();
      MAPIFolder oFolder = this.ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
      tbFolderItemCount.Text = oInbox.Folders.Count.ToString();
  }
  
  #endregion
  </code></pre>
  
  <p>Thanks for any help received! Dan</p>