none
[COM] Find folder path for a public folder, given an SMTP address RRS feed

  • Question

  • I am new to COM development, and Outlook in general, so please excuse my ignorance...

    I am trying to find out how to obtain a folder object for the delivery folder of a Public Folder.

    So say for example in Exchange, if you have a PF called "MyPF" with the path set to "\MyPF" and the email address set to "MyPF@MyDomain.com"

    In outlook, the folder structure for the PF would appear like:

    Public Folders - <username>
     +- All Public Folders
      +- MyPF
    So, what i would like is some way, via COM, to craft a function that if you pass it "MyPF@MyDomain.com" would return the COM object for the folder "Public Folders\All Public Folders\MyPF"

    Ideally, this code should be compatible with Outlook 2007 through 2016, and using C#.


    Friday, December 11, 2015 2:24 PM

All replies

  • Hello Clive,

    You can use the GetDefaultFolder method of the Namespace class. Just pass the olPublicFoldersAllPublicFolders value to get the All Public Folders folder in the Exchange Public Folders store. Then you can navigate through the tree of folders and find yours. For example, you can use the Folders property of the Folder class which returns the Folders collection that represents all the folders contained in the specified Folder. See How to: Enumerate Folders for the sample code.

    Friday, December 11, 2015 3:13 PM
  • Thanks Eugene,

    I do not see how to get a *folder name* from the SMTP address of a public folder.

    If you know what the folder name is, then yes, you can find it in this way, but if all the code has is an SMTP address, then I cannot work out what the correct folder is when I am iterating the "All Public Folders" folder.

    To clarify, the ONLY information that the code has is the SMTP address.

    So I need to be able to resolve "MyPF@MyDomain.com" to "MyPF".

    The code then iterates "All Public Folders" until it finds "MyPF".

    Friday, December 11, 2015 5:37 PM
  • Hi Clive

    >>So I need to be able to resolve "MyPF@MyDomain.com" to "MyPF".<<

    Based on my understanding, the conversion is based on your business logic. You can write your own sub to translate "MyPF@MyDomain.com" to "MyPF" with string manipulate function.

    Then we can find the root folder for the Exchange Public Folder store via Application.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders). And find the specific folder we wanted based on the public folder name we converted previously.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 14, 2015 6:15 AM
    Moderator
  • Based on my understanding, the conversion is based on your business logic. You can write your own sub to translate "MyPF@MyDomain.com" to "MyPF" with string manipulate function.

    If a public folder's address is "MyPF@somedomain.com", there is no guarantee that the name of the folder is "MyPF".

    This was just a simplified example.

    Monday, December 14, 2015 9:19 AM
  • Hi evilC1,

    Based on my understanding, the conversion is based on your business logic. You can write your own sub to translate "MyPF@MyDomain.com" to "MyPF" with string manipulate function.

    If a public folder's address is "MyPF@somedomain.com", there is no guarantee that the name of the folder is "MyPF".

    This was just a simplified example.

    Did you want to get the all public folders under the specific email address? If I understood correctly, we can make the public root folder path with the email address. Here is an example for your reference:

    Set olns = Application.GetNamespace("MAPI")
    Set accs = olns.Accounts
    For Each Account In accs
        If Account.AccountType = olExchange And Account.SmtpAddress = olns.Session.DefaultStore Then
            Set pub = olns.Folders("Public Folders" & " - " & Account.SmtpAddress)
          
        End If
    Next

    Then we can get all the public folders under that folder we get.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 15, 2015 7:24 AM
    Moderator
  • Eugene's suggestion is still the only step forward.

    I can use this to successfully find the "All Public Folders" folder:

    Outlook.MAPIFolder folder = olns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);

    But I still see no way to work out the name of the folder itself, given the SMTP address.

    And no, I don't consider doing a string split on the SMTP address a valid solution as there is no guarantee it will be correct (eg with most of ours, the folder name has a space in, but obviously the SMTP address does not)


    Tuesday, December 15, 2015 9:59 AM
  • Hi Clive,

    >>And no, I don't consider doing a string split on the SMTP address a valid solution as there is no guarantee it will be correct (eg with most of ours, the folder name has a space in, but obviously the SMTP address does not)<<

    There are no such property for the Folder object to relative to the SMTP address. Since there is no environment for we to test the other property, I suggest that you can check whether it store the relative settings via Folder.PropertyAccessor .

    If yes, we can get the root public folder and loop the subfolders and detect the folder by its property.

    And if you want to Outlook object model to support the feature to distinguish the folder by SMTP address, you can try to submit the feedback from link below:
    Outlook UserVoice

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 16, 2015 9:45 AM
    Moderator
  • In http://knicksmith.blogspot.com/2007/03/finding-public-folder-by-email-address.html the author describes using PowerShell to find a public folder from an email address.  I know it's not COM or OOM, but the method described might be informative.

    Wednesday, December 16, 2015 10:45 AM
  • Yes, thankyou, this is useful information.

    If nothing else, it should allow a workaround. It may even provide some clues as to how to do it via COM.

    Wednesday, December 16, 2015 11:11 AM
  • Hi RLWA,

    Thanks for the helpful information for this issue.

    @evilC1,

    >>If nothing else, it should allow a workaround. It may even provide some clues as to how to do it via COM.<<

    Based on the suggestion of RLWA32, we can get the folder path via the SMTP address via the Exchange API. And get the specific folder based on the folder path we got.

    And since this forum is mainly for discussing developing issues for Outlook, to get more effective response, I suggest that you reopen a new thread in Exchange Server Developer forum for the code sample for get the folder path for the public folder via SMTP address.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 17, 2015 6:58 AM
    Moderator