determine local/remote folder

R

Rasmus Watjen

When getting the folder tree from Outlook starting at NameSpace.Folders,
and then Folder.Items.Folders, etc., how can I determine whether a
folder is located in the following:

PST file
User's own mailbox
Public folders


Thank you.

Rasmus
 
K

Ken Slovak - [MVP - Outlook]

What version or versions of Outlook do you intend to support? What API's are
you using for Outlook?

If using Outlook 2003 for example you can use this:
NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders )

to get the All Public Folders folder as a MAPIFolder. You can then read the
StoreID of that folder and use it for comparison with other folders to see
if the store is a public folders store.

Using GetDefaultFolder(olFolderInbox) to get a MAPIFolder and then its
StoreID will give you the id for the default store, mailbox or PST file.

Convert the StoreID into a Byte array of binary values and then convert that
into a string. If inside the string you find "EMSMDB.DLL" it's an Exchange
store. If inside the string you find "MSPST.DLL" or "PSTPRX.DLL" it's a PST
file.
 
R

Rasmus Watjen

Ken said:
What version or versions of Outlook do you intend to support? What API's
are you using for Outlook?
I would like to support Outlook 2000 and newer. I am using the COM
interface, but the same methods should work inside Outlook in VBA.
The connection code is:
outlook = CreateOleObject('Outlook.Application');
NameSpace = outlook.GetNameSpace('MAPI');
etc.
If using Outlook 2003 for example you can use this:
NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders )
to get the All Public Folders folder as a MAPIFolder. You can then read
the StoreID of that folder and use it for comparison with other folders
to see if the store is a public folders store.
I like that way because it is simple to do on a folder-by-folder basis.
Is it possible to do something similar in versions prior to 2003? It
must support foreign language installations, so I cannot simply search
for the "Public folders" folder, it may be named something else.
Using GetDefaultFolder(olFolderInbox) to get a MAPIFolder and then its
StoreID will give you the id for the default store, mailbox or PST file.
The default folder for inbox may be located in a public folder, is that
not correct? So the store id would not be the same as a folder located
in the user's own mailbox?
Convert the StoreID into a Byte array of binary values and then convert
that into a string. If inside the string you find "EMSMDB.DLL" it's an
Exchange store. If inside the string you find "MSPST.DLL" or
"PSTPRX.DLL" it's a PST file.
That is nice to know.

Thank you for your tips so far.

Best regards,
Rasmus
 
K

Ken Slovak - [MVP - Outlook]

When you get the default Inbox folder it's always in your default mailbox or
PST file. It can never be in a non-default store or a public folder.

Unfortunately the only language-independent method of seeing if a folder is
in a public folder store uses CDO 1.21 (optional installation with Outlook
2000 and later). It can also be done with Extended MAPI (C++ or Delphi code
only) or the forthcoming version of Redemption (www.dimastr.com) using the
new RDOSession object.

CDO 1.21 code would look something like this:

Public Function IsPublicFoldersStore(strStoreID As String) As Boolean
Dim g_objCDO As MAPI.Session
Dim objRootFolder As MAPI.Folder
Dim objField As MAPI.Field
Dim objStore As MAPI.InfoStore

On Error Resume Next

Set g_objCDO = CreateObject("MAPI.Session")
g_objCDO.Logon "", "", False, False

Set objStore = g_objCDO.GetInfoStore(strStoreID)

With objStore
If .ProviderName = "Microsoft Exchange Server" Then
Set objRootFolder = .RootFolder
If objRootFolder.Name = "IPM_SUBTREE" Then
Err.Clear
Set objField = .Fields.Item(PR_IPM_PUBLIC_FOLDERS_ENTRYID)
If Err Then
IsPublicFoldersStore = False
Else
If objField <> "" Then
IsPublicFoldersStore = True
Else
IsPublicFoldersStore = False
End If
End If
Else
IsPublicFoldersStore = False
End If
Else
IsPublicFoldersStore = False
End If
End With

Set objRootFolder = Nothing
Set objField = Nothing
Set objStore = Nothing
End Function
 
Top