views:

162

answers:

1

I have some code that locates all the contact folders that a user has access to by iterating through the Application.Session.Stores collection.

This works for the user's contacts and also all the public contacts folders. It also finds all the contacts folders in additional mailbox accounts that the user has added via the Tools -> Account Settings... menu command.

However, this requires the user to have full access to the other person's account. When a user only has access to another person's contacts, then that person's contacts show up under the "People's Contacts" group in the Contacts view. How do I find those contact folders that don't show up under Session.Stores?

In order to see the other user's contacts folder without adding access to their full mailbox, click File -> Open -> Other User's Folder... from the Outlook menu. In the dialog box, enter the other user's name and select Contacts from the Folder type drop down list.

Here's the code (minus the error checking and logging) I'm using to find a list of all the user's Outlook contact folders. I know this can (and maybe should) be done using early binding to the Outlook.Application type, but that doesn't affect the results. EnumerateFolders is recursive so that it searches all sub folders.

Dim folderList = New Dictionary(Of String, String)
Dim outlookApp = CreateObject(Class:="Outlook.Application")
For Each store As Object In outlookApp.Session.Stores
    EnumerateFolders(folderList, store.GetRootFolder)
Next

Private Sub EnumerateFolders(ByRef folderList As Dictionary(Of String, String), ByVal folder As Object)
    Try
        If folder.DefaultItemType = 2 Then
            folderList.Add(folder.EntryID, folder.FolderPath.Substring(2))
        End If

        For Each subFolder As Object In folder.Folders
            EnumerateFolders(folderList, subFolder)
        Next
    Catch ex As Exception

    End Try
End Sub
+2  A: 

Since I didn't get any answers here, (actually earned the Tumbleweed badge for this one) I asked this question over on the msdn forums.

http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/9edb0bdf-a7cb-451b-b1b4-99c6ec1f8214/

Here's the answer:

In Outlook 2007 or later, go through the navigation pane. For an overview, see http://msdn.microsoft.com/en-us/library/bb206757.aspx. The sample at http://msdn.microsoft.com/en-us/library/bb176429.aspx shows how to iterate all the navigation groups within the Calendar module. Each NavigationFolder has a Folder object property that returns the actual Folder from the other user's mailbox (or other store).

That will get you all the folders the user is actively working with. If you want all folders they theoretically have access to, you can iterate the entries in the GAL and for each one, attempt to execute Namespace.GetSharedDefaultFolder. If the folder can't be returned, the user doesn't have access.

Now that I've seen this, I think I'm going to use the ContactsModule for finding all the contact folders instead of searching for contacts folders within all the folders in the store. Should be much faster.

Dennis Palmer