Outlook Creating PST File and using Webview

Add-in Express™ Support Service
That's what is more important than anything else

Outlook Creating PST File and using Webview
How to... 
David Golden




Posts: 11
Joined: 2006-03-07
Hey all,

I've been trying to create something which I think is quite simply yet I have a few issues that I've been unable to get around. All I want (well the first part) is for my add-in to...

1. Create a users PST with their email address as the name of the PST File (if it exists - well Outlook handles that).
2. Create 2 folders (one an "Inbox" type Folder and another a "Sent Items" type Folder) if they don't exist.
3. Set the Main Folder to a webview (as default)
4. Override the "open in which folder" and open to the Webview of this new PST File.

So far, I've doing most of these items, but I'm having trouble with
1. Figuring out exactly which store is the new one just created.
2. Renaming the new store. I can set the name fine, but it doesn't update in the folder list.
3. Have the main Store folder always set to open the webpage by default.
4. I can override which folder opens, but its very 'flashy' for want of a better word. It closes the Outlook window and opens another, and when a new email is received another Outlook Explorer opens.
5. Making my Sent Items folder have the same icon as Sent Items and have the Sent instead of Received column.

I've been pulling my hair out over these items, and decided it was time to ask.

Here is my Initialise code as it stands...


procedure TAddInModule.adxCOMAddInModuleAddInInitialize(Sender: TObject);
var
  sPSTPath: string;
begin
  sexePath:= COMAddInClassFactory.filepath;
  case HostType of
    ohaExcel: begin
      ExcelApp.OnWorkbookBeforeSave := DoOnWorkbookBeforeSave;
    end;
    ohaWord: begin
      WordApp.OnDocumentBeforeSave := DoOnDocumentBeforeSave;
    end;
    ohaOutlook: begin
      sPSTPath:= sexePath + 'older' + outlookapp.GetNamespace('MAPI').CurrentUser.Address + '.pst';
      if FileExists(sPSTPath) then
        IFolder:= OutlookApp.GetNamespace('MAPI').Folders.Item('Newstore')
      else begin
        OutlookApp.OnItemSend := DoItemSend;
        OutlookApp.GetNamespace('MAPI').AddStore(sPSTPath);
        IFolder := OutlookApp.GetNamespace('MAPI').Folders.GetLast;
        IFolder.Name:= 'Newstore;
        IFolder.Description:= 'Email Cabinet for Documents';
        IFolder.WebViewAllowNavigation:= True;
        IFolder.WebViewOn:= True;
        IFolder.WebViewURL:= sexePath + 'folderOLToday.html';
        if (IFolder.Folders.Count = 1) and (IFolder.Folders.Item('1').Name = 'Deleted Items') then begin
          IFolder.folders.Add('Received Emails', olFolderInbox);
          IFolder.folders.add('Sent Emails', olFolderInbox);
        end;
      end;
    end;
  end;
end;


Any help into these items would be greatly appreciated, while I continue my struggle with Outlook! ;) :D

Thanks

David.
Posted 15 Mar, 2006 01:19:26 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi David,

1. It seems to be done in your code. You use the GetLast method after adding a store.

2. Try to remove and re-add the store after renaming. See the code below:

  OutlookApp.GetNamespace('MAPI').AddStore('c:
ew.pst');
  Folder := OutlookApp.GetNamespace('MAPI').Folders.GetLast;
  Folder.Name := 'NewStore';
  Folder.Description = 'Description';
  OutlookApp.GetNamespace('MAPI').RemoveStore(Folder);
  OutlookApp.GetNamespace('MAPI').AddStore('c:
ew.pst');


3. Again, you have it in your code. Just set the WebViewURL property first, and then the WebViewOn property.

4. I do not quite understand what you want to do here. Please specify.

5. As to icons, I am afraid it is impossible. At least I don't see the way of doing this. As to Sent instead of Received column, you can try to work with the MAPIFolder.Views collection (note, it exists in Outlook XP and higher).

Posted 15 Mar, 2006 11:08:41 Top
David Golden




Posts: 11
Joined: 2006-03-07
Hi Dmitry,

You are a Office legend my friend, thanks for all of that so far!
With number 4. When Outlook Opens I would like the add-in to move the focus to the new store, and the new Webview that has been enabled.

Is there a way to do that without closing the preview explorer and displaying the new one...

I've tried just going iFolder.Display, but this never seems to work (doesn't seem to work in that it opens another explorer.

Also with the MAPIFolder.View is that possible to access with ADX2.4 VCL? Doesn't the VCL use the 2000 OutlookApplication? or does it use whichever version is installed?

Thanks again,

David.
Posted 15 Mar, 2006 16:38:10 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi David,

4. After you change the WebView on the new folder you can use the CurrentFolder method of the _Explorer interface to make the folder active.
Also, you may have a look at the following MSDN article. I think it will be helpful for Outlook 2000 and 2002.
http://support.microsoft.com/?kbid=305093


Also with the MAPIFolder.View is that possible to access with ADX2.4 VCL? Doesn't the VCL use the 2000 OutlookApplication? or does it use whichever version is installed?


You can try to use the code similar to the one below:

var
  IViews: OLEVariant;
begin
  try
    IViews := OLEVariant(OutlookApp.ActiveExplorer.CurrentFolder).Views;
    // TODO
  except
    // oops... Outlook 2000 doesn't have this property
  end;
end;
Posted 16 Mar, 2006 07:34:08 Top