467,161 Members | 1,033 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

MAPI Folder Tree Navigation

In effort to understand (Outlook) MAPI folder tree
structure wrote simple linear code below to navigate
tree.

Successive "...Folders.GetNext()"'s return same folder at
all levels of tree. What am I doing wrong or not
understanding?

Thanks.

OUTPUT:
There are 4 root folders.
Root Folder 1 name: Public Folders
Public Folders contains 2 folders.
Level 1 folder 1 name: Favorites
Level 1 folder 2 name: All Public Folders
Level 1 folder 3 name: All Public Folders
Level 1 folder 4 name: All Public Folders
Root Folder 2 name: Mailbox - Doe, John
Mailbox - Doe, John contains 15 folders.
Level 1 folder name: Calendar
Level 1 folder name: Contacts
Level 1 folder name: Contacts
Root folder 3 name: Mailbox - Doe, John
....

CODE:
Private Sub btnGo_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnGo.Click
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim oRootFolder As Outlook.MAPIFolder
Dim oFolder As Outlook.MAPIFolder
Dim strText As New System.Text.StringBuilder()

olApp = CreateObject("Outlook.Application")
olNS = olApp.GetNamespace("MAPI")

'Get root MAPIFolder
strText.Append("There are " & olNS.Folders.Count
() & " root folders." & vbCrLf)
oRootFolder = olNS.Folders.GetFirst()
strText.Append("Root Folder 1 name: " &
oRootFolder.Name & vbCrLf)
strText.Append(vbTab & oRootFolder.Name.ToString
() & " contains " & oRootFolder.Folders.Count.ToString()
& " folders." & vbCrLf)

'Get next level MAPIFolder
oFolder = oRootFolder.Folders.GetFirst()
strText.Append(vbTab & "Level 1 folder 1 name: "
& oFolder.Name & vbCrLf)
oFolder = oRootFolder.Folders.GetNext()
strText.Append(vbTab & "Level 1 folder 2 name: "
& oFolder.Name & vbCrLf)
oFolder = oRootFolder.Folders.GetNext()
strText.Append(vbTab & "Level 1 folder 3 name: "
& oFolder.Name & vbCrLf)
oFolder = oRootFolder.Folders.GetNext()
strText.Append(vbTab & "Level 1 folder 4 name: "
& oFolder.Name & vbCrLf)

'Get next root MAPIFolder
oRootFolder = olNS.Folders.GetNext()
strText.Append("Root Folder 2 name: " &
oRootFolder.Name & vbCrLf)
strText.Append(oRootFolder.Name & " contains " &
oRootFolder.Folders.Count.ToString() & " folders." &
vbCrLf)

'Get next level MAPIFolder
oFolder = oRootFolder.Folders.GetFirst()
strText.Append(vbTab & "Level 1 folder name: " &
oFolder.Name & vbCrLf)
oFolder = oRootFolder.Folders.GetNext()
strText.Append(vbTab & "Level 1 folder name: " &
oFolder.Name & vbCrLf)
oFolder = oRootFolder.Folders.GetNext()
strText.Append(vbTab & "Level 1 folder name: " &
oFolder.Name & vbCrLf)

'Get next root MAPIFolder
oRootFolder = olNS.Folders.GetNext()
strText.Append("Root folder 3 name: " &
oRootFolder.Name & vbCrLf)

rtxtShow.Text = strText.ToString()
End Sub

Nov 15 '05 #1
  • viewed: 2985
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Oleg Safronov via .NET 247 | last post: by
6 posts views Thread by Dennis Allen | last post: by
reply views Thread by Tomas Brabenec | last post: by
reply views Thread by OSI Mik | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.