By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

MAPI Folder Tree Navigation

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.