AdvancedSearch & PSTs

  • Thread starter Thread starter Tim Pulley
  • Start date Start date
T

Tim Pulley

I need to programmatically create a Search Folder in a PST that includes the
PST's root folder. I can create a Search Folder using AdvancedSearch for any
of the PST's subfolders but cannot find folder path string for the root
folder that works.. Using the Outlook UI I can create a Search Folder that
includes the PST's root folder, so it's possible to do this.

Here's the script I'm running in the OutlookSpy Application object's Script
tab.


Dim scope
Dim filter
Dim srchFldrName
Dim srchSubFldrs
Dim srch
Dim srchFldr


scope = "'\\Personal Folders'"

filter = "( http://schemas.microsoft.com/mapi/proptag/0x001A001E Like
'IPM.Post.%' )"

srchSubFldrs = true

srchFldrName = "TSF - " & Now

Debug.Print "Search Folder Name: " + srchFldrName


Set srch = Application.AdvancedSearch( scope, filter, srchSubFldrs,
srchFldrName )

' BrowseObject( srch )

If Not srch is Nothing Then

Set srchFldr = srch.Save( srchFldrName )

End If


If scope is set to just the root folder name, '\\Personal Folders', the call
to create the Search object succeeds but the call to save it fails with the
following error:

Error calling Save()

Return code 0x80020009

The operation failed. An object could not be found.

Using a scope string such as \\Personal Folders\Top of Information Store
causes the call to create the Search object to fail.

Does anyone have any suggestions?
 
Hi Ken,



I can create a search folder for an Exchange mailbox using '\\Mailbox -
UserName' for the scope param (the equivalent of Inbox.Parent.Name). This
creates a search folder rooted at the top of the user's mailbox (the "Top of
Information Store" folder in MAPI parlance). I want to do the same thing for
PSTs.



This is a just a plain PST. It doesn't have an Inbox. The folder structure,
in Outlook, looks like this



Personal Folders

| - Deleted Items

| - Search Folders

| - Folder1



The folder path for the root folder is '\\Personal Folders'.



If I use '\\Personal Folders\Folder1' or '\\Personal Folders\Deleted Items'
for the AdvancedSearch scope param I can create a search folder. If I use
just '\\Personal Folders' for the scope param AdvancedSearch returns a
Search object but the call to Search.Save( folderName) fails.



If I create a search folder using '\\PersonalFolders\Folder1' for the scope
param I can modify it, using the Outlook UI, to search from the root of the
PST. I just need to do this programmatically




Tim
 
I don't know. I took your code and made it into a macro by putting it in a
Sub and it worked with no errors, and it saved the search as a search
folder. I didn't try running it as an OutlookSpy script though. The only
change I made to the code was just to put it in the Sub.

I tested the code on both Outlook 2007 and 2003.
 
Ken,

It's working for you because the PST is configured as the default mail
delivery location. When the PST is configured as the default mail delivery
location the call to save the search succeeds. It fails if the PST is not
the default mail delivery.

I've tried this on multiple VMs and always get the same result.

I originally coded this in C# and as part our apps Outlook add-in and
encountered the problem when I started testing. I then tried it as script in
OutlookSpy and got the same results. I've tested using PSTs created with
Outlook 2003 and Outlook 2007 RTM and SP2 with Outlook 2007 RTM and SP2.
 
I'll have to check again using a non-default PST file.

If you're using Redemption you can directly create a search folder without
using AdvancedSearch and saving the search. I don't know if that helps you
at all, but it's worth throwing on the table.
 
Back
Top