Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#120: How can I retrieve a folder list from MS Outlook?

I want to post a few tips which are replated to MS Outlook application and interaction with it from Delphi. The procedure below allow to load a tree of available folders into TTreeView:

procedure TfrmMain.RetrieveOutlookFolders(tvFolders: TTreeView);

  procedure LoadFolder(ParentNode: TTreeNode; Folder: OleVariant);
  var
    i: Integer;
    node: TTreeNode;
  begin
    for i := 1 to Folder.Count do
    begin
      node := tvFolders.Items.AddChild(ParentNode, Folder.Item[i].Name;

      LoadFolder(node, Folder.Item[i].Folders);
    end;
  end;

var
  outlook, NameSpace: OLEVariant;
begin
  outlook := CreateOleObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');

  LoadFolder(nil, NameSpace.Folders);

  outlook := UnAssigned;
end;

A few comments:
1. the data in Outlook have the next structure: outlook application defines a MAPI's namespace which have a collection of folders. Each folder contains an items or sub-folders

2. this code load a full tree in TreeView. Of course, if you have a lot of pst-files with messages (active, archive, backup etc) and each of this pst-file have a large structure of folders, this code will work slowly. So as suggestion: you can rewrite a code and load the one level only. In this case code will work quickly and a list of sub-folders you'll receive in OnExpanding event of your TreeView

3. each folder of Outlook have an unique idenifier. You can save it somewhere (for example, in Data property of TTreeNode). Remember that this ID is long string value which you can receive as EntryID in loop of LoadFolder procedure: Folder.Item[i].EntryID

PS: if this topic is interested for you, I'll continue this serie of tips and shall show how to load the messages/contacts/tasks/etc from some folder or create a new item.


Published: May 25, 2001

See also
 
dBase Viewer
SMImport suite
Protected Storage Viewer
SMDBGrid
Excel Reader (dll)
Clarion Viewer
SMExport suite
Viewer for TNEF-files (winmail.dat)
ABA Database Convert
Paradox to MS Access converter
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising