none
Search Folder Location RRS feed

  • Question

  • I created a search folder with AdvancedSearch(), and after I call Save() on it, the folder is placed into the SearchFolder in outlook. I was wondering if it was possible to move these folders to a different location. What I am trying to do is create multiple search folders with different filters and place them into other sub folders in different areas. Is this possible? Thanks.

    Tuesday, May 7, 2013 8:57 AM

Answers

  • Outlook stores searches as hidden message with the search definitions. The actual search folder is created in the search root folder, which is outside of the IPM root folder and hence not visible to the end user - you can see this in OutlookSpy if you click IMsgStore button, then "Open Root Folder". If the search folder hasn't been accessed for a while, the search folder (which is expensive) is deleted and only the hidden message with the search definition is left. Such folders are show italicized by Outlook.

    However, the search folders do not have to be created in the search root folder and they do not need to be associated with Outlook searches, you can freely mix search folders with the regular folders. Unfortunately Outlook Object Model does not expose raw search folders, you would need to use Extended MAPI (C++ or Delphi) or Redemption (any language) to create or access such folders.

    If using Redemption is an option, you can create a search folder using the RDOSearchFolder object. The below script can be launched from OutlookSpy (click Script button, paste the script, click Run):

    'create new search folder
     set Session = CreateObject("Redemption.RDOSession")
     Session.MAPIOBJECT = Application.Session.MAPIOBJECT
     set DefaultStore = Session.Stores.DefaultStore
     set SearchRootFolder = DefaultStore.IPMRootFolder'DefaultStore.SearchRootFolder
     set NewSearchFolder = SearchRootFolder.Folders.AddSearchFolder("Test Redemption Search Folder")
    'set the restriction to search for messages with the word "test" in the subject line
     NewSearchFolder.SearchCriteria.AsSQL = "Subject LIKE '%test%' "
    'specify that the search should be performed in the Inbox and Sent Items folders
     NewSearchFolder.SearchContainers.Add(DefaultStore.GetDefaultFolder(olFolderInbox))
     NewSearchFolder.SearchContainers.Add(DefaultStore.GetDefaultFolder(olFolderSentMail))
    'specify the search flags
     NewSearchFolder.IsRecursiveSearch = false
     NewSearchFolder.IsForegroundSearch = false
    'we are all set: set the search parameters and let the fun begin!
     NewSearchFolder.Start



    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, May 7, 2013 6:11 PM
  • See my reply to your other post at http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/2576f05a-96a9-46c5-839d-06c7bfda0a77

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, May 8, 2013 5:51 AM

All replies

  • No, that's not possible using the Outlook object model.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "FlexSquad" <=?utf-8?B?RmxleFNxdWFk?=> wrote in message news:7d27b0dd-64d5-4ca9-b57e-e63933b6857f...

    I created a search folder with AdvancedSearch(), and after I call Save() on it, the folder is placed into the SearchFolder in outlook. I was wondering if it was possible to move these folders to a different location. What I am trying to do is create multiple search folders with different filters and place them into other sub folders in different areas. Is this possible? Thanks.


    Ken Slovak MVP - Outlook
    Tuesday, May 7, 2013 2:45 PM
    Moderator
  • Even if the physical search folder is created in a different folder, Outlook displays searches in a flat list, you cannot have any hierarchical structure.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, May 7, 2013 2:45 PM
  • Ah, thanks. What I am trying to do is have a "Project A" folder, and when the user clicks that folder, all emails that have certain keywords set for that project get displayed in that folder. Any ideas on the best way to do this? Thanks.
    Tuesday, May 7, 2013 5:44 PM
  • Outlook stores searches as hidden message with the search definitions. The actual search folder is created in the search root folder, which is outside of the IPM root folder and hence not visible to the end user - you can see this in OutlookSpy if you click IMsgStore button, then "Open Root Folder". If the search folder hasn't been accessed for a while, the search folder (which is expensive) is deleted and only the hidden message with the search definition is left. Such folders are show italicized by Outlook.

    However, the search folders do not have to be created in the search root folder and they do not need to be associated with Outlook searches, you can freely mix search folders with the regular folders. Unfortunately Outlook Object Model does not expose raw search folders, you would need to use Extended MAPI (C++ or Delphi) or Redemption (any language) to create or access such folders.

    If using Redemption is an option, you can create a search folder using the RDOSearchFolder object. The below script can be launched from OutlookSpy (click Script button, paste the script, click Run):

    'create new search folder
     set Session = CreateObject("Redemption.RDOSession")
     Session.MAPIOBJECT = Application.Session.MAPIOBJECT
     set DefaultStore = Session.Stores.DefaultStore
     set SearchRootFolder = DefaultStore.IPMRootFolder'DefaultStore.SearchRootFolder
     set NewSearchFolder = SearchRootFolder.Folders.AddSearchFolder("Test Redemption Search Folder")
    'set the restriction to search for messages with the word "test" in the subject line
     NewSearchFolder.SearchCriteria.AsSQL = "Subject LIKE '%test%' "
    'specify that the search should be performed in the Inbox and Sent Items folders
     NewSearchFolder.SearchContainers.Add(DefaultStore.GetDefaultFolder(olFolderInbox))
     NewSearchFolder.SearchContainers.Add(DefaultStore.GetDefaultFolder(olFolderSentMail))
    'specify the search flags
     NewSearchFolder.IsRecursiveSearch = false
     NewSearchFolder.IsForegroundSearch = false
    'we are all set: set the search parameters and let the fun begin!
     NewSearchFolder.Start



    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, May 7, 2013 6:11 PM
  • Thanks for guiding me. One last issue with this. I have the following code(C# version)

    RDOSession session = new RDOSession();
    session.MAPIOBJECT = Singleton.Instance.GetApp().Session.MAPIOBJECT;
    RDOStore DefaultStore = session.Stores.DefaultStore;
             
    RDOFolder SearchRootFolder = session.GetFolderFromPath("\\\\fullmetalstobber@gmail.com");
    
    RDOSearchFolder NewSearchFolder = SearchRootFolder.Folders.AddSearchFolder("NEWFOLDER");
                
    NewSearchFolder.SearchCriteria.AsSQL = "Subject LIKE '%facebook%'";
                NewSearchFolder.SearchContainers.Add(session.GetFolderFromPath("\\\\fullmetalstobber@gmail.com\\Inbox"));
                         
    NewSearchFolder.IsRecursiveSearch = true;
    NewSearchFolder.IsForegroundSearch = false;
    NewSearchFolder.Start();

    I am just trying to add an RDO search folder in my fullmetalstobber@gmail.com profile, but I am getting the following exception.

     

    Error in IMAPIFolder.SetSearchCriteria: MAPI_E_EXTENDED_ERROR
    ulVersion: 0
    Component: Outlook Data File
    ulLowLevelError: 0
    ulContext: 269025537


    I am assuming that it has to do with something in session using Outlook Data File instead of fullemtalstobber@gmail.com, but I am extremely new to outlook programming, and don't know how I would change my application to use a different store(I don't know if I am using the word store properly). Any input? Thank you so much.

    Tuesday, May 7, 2013 9:03 PM
  • See my reply to your other post at http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/2576f05a-96a9-46c5-839d-06c7bfda0a77

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, May 8, 2013 5:51 AM