AdvancedSearch & PSTs

Status
Not open for further replies.
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?
 
Get Inbox.Parent.Name and use that.

"Tim Pulley" <tpulley_at_mantech-ist_dot_com> wrote in message

news:%237DIiuOJKHA.5984@TK2MSFTNGP05.phx.gbl...
> 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
<kenslovak@mvps.org> wrote in message

news:e2BPHOPJKHA.1376@TK2MSFTNGP02.phx.gbl...
> Get Inbox.Parent.Name and use that.

> >

>

> "Tim Pulley" <tpulley_at_mantech-ist_dot_com> wrote in message
> news:%237DIiuOJKHA.5984@TK2MSFTNGP05.phx.gbl...
> >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?
>

>>

>
 
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.

"Tim Pulley" <tpulley_at_mantech-ist_dot_com> wrote in message

news:ukBH5zPJKHA.1380@TK2MSFTNGP02.phx.gbl...
> 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
 
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.
<kenslovak@mvps.org> wrote in message

news:emPumrYJKHA.1252@TK2MSFTNGP04.phx.gbl...
> 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.

> >

>

> "Tim Pulley" <tpulley_at_mantech-ist_dot_com> wrote in message
> news:ukBH5zPJKHA.1380@TK2MSFTNGP02.phx.gbl...
> > 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'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.

"Tim Pulley" <tpulley_at_mantech-ist_dot_com> wrote in message

news:u7nhiymJKHA.4236@TK2MSFTNGP04.phx.gbl...
> 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.
>
 
Status
Not open for further replies.

Similar threads

Back
Top