Custom Search Folder

D

doru00

Hi!

I would like to know if there is any way to programatically create
your own custom Search Folder from an Outlook add-in, and of course,
add it's own search criteria (I would like to search after a custom
fileld added in certain MailItems). Also, if this is possible, how do I
access it afterwards?
It doesn't matter if this is done via OOM, CDO or Redemption (or
something else?)...is it possible?

Thanks a lot,
Doru
 
S

Sue Mosher [MVP-Outlook]

Use the Application.AdvancedSearch method to return a Search object, then use Search.Save to create the search folder. You will be able to use a custom field in the search criteria only if it is defined in the folder(s), not just in individual items.

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
D

doru00

Wow! That works like a charm! Thanks a lot! :) I can now create my own
Search Folder, but I still don't understand if, and how can I:
1) programatically find it,
2) edit it if needed (i.e. if the user manually modified it in the
mean time),
3) eventually delete it (will be needed on add-in uninstall).

Thanks again,
Doru
 
S

Sue Mosher [MVP-Outlook]

Since the Search.Save function returns a MAPIFolder object, you should be able to get that folder's EntryID at that point for later use with the Namespace.GetFolderFromID method.

You will not be able to edit the search folder settings programmatically. I think you'll be able to delete it, but I haven't tried it.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
K

Ken Slovak - [MVP - Outlook]

Yeah, you have to get it, delete it and then re-create it if you want to
change the filter. I've done that a lot.




Since the Search.Save function returns a MAPIFolder object, you should be
able to get that folder's EntryID at that point for later use with the
Namespace.GetFolderFromID method.

You will not be able to edit the search folder settings programmatically. I
think you'll be able to delete it, but I haven't tried it.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
K

Ken Slovak - [MVP - Outlook]

You can't set up a searchfolder that searches across multiple mail stores
(PST files or Exchange mailboxes). Each searchfolder can only search within
its own store.

For a search of a PST file that starts with the top of store and includes
all subfolders use a search string something like this (depending on the
name of your top of store):

strSearch = "'//Personal Folders'"

Note that since there's a space in "Personal Folders" I surrounded it with
single quotes.

Then you would set the SearchSubfolders argument = True.
 
D

doru00

This all works fine, but how can I programatically save my search
folder in a DIFFERENT store then the default one (i.e. Personal
Folders). Probably it's the name parameter in the Save method of the
search object - search_object.Save("name_here"), but I just can't
figure it out.
Thanks!
 
S

Sue Mosher [MVP-Outlook]

You can't. Search folders are not actual MAPI folders. They are stored search queries and live in the default store as hidden items.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
D

dorutzu

But isn't there any way to do this, even with CDO or Redemption? If the user
can do this manually, I belive there should be a way to do this
programatically as well. Also, it seems that I can create a (invalid,
unfortunatelly) search folder in a custom storage via MFCMapi. Any futher
ideas regarding this issue?
Thanks again!
 
K

Ken Slovak - [MVP - Outlook]

Code would have to log into that other store and create the search folder in
that other store and save it there.

A search folder, to be technical, is a folder that contains a MAPI
Restriction. That restriction applies only to items in the store and the
store must be able to support searches like that. The PR_STORE_SUPPORT_MASK
property in a store (IMsgStore) must have the STORE_RESTRICTION_OK flag set
in that property to be able to use a search folder.

If that flag bit isn't set you cannot create a search folder in that store.
An example of a store like that is Exchange public folders. You just cannot
create a search folder in a public folder store, no matter what API you use,
including Extended MAPI (CDO and Redemption just wrap Extended MAPI as COM
objects).

Some alternate store providers might also not support STORE_RESTRICTION_OK.

You mention a user doing it manually, I defy you to manually create a search
folder in PST file A that works on PST file B. You just can't. Unless and
until the design of MAPI stores is moved from the modified JET database they
now use into SQL server there isn't even the possibility of doing that.

If you want to explore these things I highly recommend using either MFCMAPI
from MS or OutlookSpy from the author of Redemption. Both are client side
tools that let you dig into all those MAPI things that Outlook hides from
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top