Guest User

Untitled

a guest
May 24th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Microsoft.Office.Interop.Outlook.Application app = null;
  2. Microsoft.Office.Interop.Outlook._NameSpace ns = null;
  3.  
  4. private void button1_Click(object sender, EventArgs e)
  5. {
  6. app = new Microsoft.Office.Interop.Outlook.Application();
  7. ns = app.GetNamespace("MAPI");
  8. MessageBox.Show(countRootFolders().ToString());
  9. }
  10.  
  11. public int countRootFolders()
  12. {
  13. Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = this.ns.Session.DefaultStore.GetRootFolder();
  14. int rootCount = rootFolder.Folders.Count;
  15.  
  16. foreach (Microsoft.Office.Interop.Outlook.MAPIFolder subfolder in rootFolder.Folders)
  17. {
  18. rootCount += subfolder.Folders.Count;
  19. }
  20.  
  21. return rootCount;
  22. }
  23.  
  24. public int countRootFolders(Microsoft.Office.Interop.Outlook.MAPIFolder aFolder)
  25. {
  26. int rootCount = aFolder.Folders.Count;
  27.  
  28. foreach (Microsoft.Office.Interop.Outlook.MAPIFolder subfolder in aFolder.Folders)
  29. {
  30. rootCount += countRootFolders( subFolder );
  31. }
  32.  
  33. return rootCount;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment