none
Predicting name of Public Folders top-level folder RRS feed

  • Question

  • I have a program that reads the contact information from a folder beneath the Public Folders folder. In order to access the folder, it needs to know the full path leading down to it. In Outlook 2003, this was no problem since all the folder names were the same for everyone. With Access 2010, the top folder name appears to be personalized and where I work it is not consistently named. For some users, it is named 'Public Folders - <userid>' and for some 'Public Folders - <email address>'. For all I know there may be other variations. Does anyone know where it gets the appended part from so I can reliably construct the name of this folder and thus the path leading doen to the folder I need to read? Thanks.
    Tuesday, April 9, 2013 4:13 PM

Answers

  • Use NameSpace.CurrentUser to construct the "Public Folders - <username>" prefix.

    Ideally though you'd use NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders), then you wouldn't need to build the path. Just "walk" Folder.Folders until you get the folder you want.  Or even better, cache the EntryID and StoreID values and use NameSpace.GetFolderFromID.

    NameSpace.GetDefaultFolder Method (Outlook)
    http://msdn.microsoft.com/en-us/library/ff866724(v=office.14).aspx


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, April 9, 2013 4:33 PM
    Moderator

All replies

  • Use NameSpace.CurrentUser to construct the "Public Folders - <username>" prefix.

    Ideally though you'd use NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders), then you wouldn't need to build the path. Just "walk" Folder.Folders until you get the folder you want.  Or even better, cache the EntryID and StoreID values and use NameSpace.GetFolderFromID.

    NameSpace.GetDefaultFolder Method (Outlook)
    http://msdn.microsoft.com/en-us/library/ff866724(v=office.14).aspx


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, April 9, 2013 4:33 PM
    Moderator
  • Accessing anything by name is never a good idea - what do you do in a localized version of Outlook?

    What you can do is loop through all stores in the Namespace.Stores collection and look for a store with Store.ExchangeStoreType == OlExchangeStoreType.olExchangePublicFolder. You can then use Store.GetRootFolder, then drill your way down.

    Another question is what do you do if you have multiple Exchange accounts with multiple PF stores in the profile?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!


    Tuesday, April 9, 2013 4:46 PM
  • I'm sure what you say is correct but I am not dealing with a heavy-duly application here. This program is used by one or two people at most and simply reads the contact information from one folder and loads it into a Microsoft Access database. I'll play around with your suggestions if I get some spare time. Thanks for the suggestions.
    Tuesday, April 9, 2013 6:14 PM
  • NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders) gives me 'All Public Folders' which is of no use.

    NameSpace.CurrentUser gives me a name in Lastname, Firstname format which again is of no use.

    I need to get the name of the top level folder which is 'Public Folders - <userid>' (or for some people is 'Public Folders - <email address>') as mentioned in my original post.

    Maybe I am missing something here but I am far from being an Outlook programmer. Maybe you could give me some sample code of how I walk through the folders.



    Tuesday, April 9, 2013 6:29 PM
  • Ok here is my modified code. It seems a convoluted way to reach the desired folder. The old code located it directly by using the entire path in one statement:

    Set olmyApp = CreateObject("Outlook.Application")
    Set olmyNameSp = olmyApp.GetNamespace("MAPI")
    '
    ' Get default public folder and loop thru all lower level folders
    ' until reach Hawaii Contacts folder.
    '
    Set olFolder = olmyNameSp.GetDefaultFolder(olPublicFoldersAllPublicFolders)
    Set olmyFolders = olFolder.Folders
    k = 0
    For i = 1 To olmyFolders.Count
       If olmyFolders.Item(i).Name = "Hawaii" Then
          'MsgBox "Found Hawaii folder"
          Set olmyFolders = olmyFolders.Item(i).Folders
          For j = 1 To olmyFolders.Count
             If olmyFolders.Item(j).Name = "Hawaii Contacts" Then
                'MsgBox "Found Hawaii Contacts folder"
                Set olHiCs = olmyFolders.Item(j).Items
                k = j
                Exit For
             End If
          Next
          Exit For
       End If
    Next
    If k = 0 Then
       MsgBox "Hawaii Contacts folder not found in Outlook." & vbCrLf & vbCrLf & _
              "- Cannot import Hawaii clients", , "Error"
       Exit Sub
    End If

    ' Read Hawaii Contacts folder and update Client table
    For i = 1 To olHiCs.Count

    ......

    Tuesday, April 9, 2013 7:32 PM
  • There is absolutely no reason to loop through the folders - Folders.Item takes an integer index as well as the subfolder name (string);

    Set olFolder = olmyNameSp.GetDefaultFolder(olPublicFoldersAllPublicFolders)
    Set olHiCs = olFolder.Folders("Hawaii").Folders("Hawaii Contacts").Items


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, April 9, 2013 8:03 PM