none
c# Outlook GetFolders() RRS feed

  • Question

  • Hi! I'm try to get all available for search folders in outlook. All fine but when I work with exchange account in outlook there is a situation when I get sum folder but when a try to search items in it with method AdvancedSearch(folderPath, filter, false, advancedSearchTag) it don't work and return exception "Operation failded". May be outlook folders have some property indicated that I can't search in that folder (because have not permissions or something else)?

    • Edited by Mickael-M-V Monday, October 14, 2013 7:11 AM
    Monday, October 14, 2013 7:02 AM

Answers

  • Can you identify which folder exactly causes the problem to manifest itself?

    If you want to search through all folders in a store, you really need to start with the root folder of the store and make sure SearchSunfolders parameter is true.

    If you need to exclude certain folders, you need to specify that in the search criteria through the PR_PARENT_ENTRYID (DASL name http://schemas.microsoft.com/mapi/proptag/0x0E090102) condition <> 'TheEntryIDValue'


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

    • Marked as answer by Mickael-M-V Thursday, October 17, 2013 5:20 AM
    Tuesday, October 15, 2013 1:06 AM

All replies

  • Where do these folders come from? Are they in the primary or a delegate mailbox?

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

    Monday, October 14, 2013 2:35 PM
  • this code demonstrate how I get folders

    Outlook.Store store;

    var rootFolders = store.GetRootFolder().Folders;

    List<Folder> GetAllFolders(rootFolders )

    {

    List<Folder> folders = new List<Folder>();

      foreach (Outlook.Folder fldr in rootFolders )

      {

         folders.Add(flsr);

         if(fldr.Folders != null)

         {

            folders.AddRange(GetAllFolders(fldr.Folders))

         }

      }

    return folders;

    }

    p.s. Thank you for help!




    • Edited by Mickael-M-V Monday, October 14, 2013 3:18 PM
    Monday, October 14, 2013 3:13 PM
  • Ok, but where does the store variable come from?

    Why exactly are you opening *all* folders in a store? You can end up with thousands of folders.


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

    Monday, October 14, 2013 4:11 PM
  • 1)"but where does the store variable come from?"

    folder = (Outlook.Folder)Outlook.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    var storeID = folder.StoreID;
    
    Outlook.Store store = Outlook.GetStoreFromID(folder.StoreID);

    2) "Why exactly are you opening *all* folders in a store? You can end up with thousands of folders."

    I need to load all items for user default account. I use method AdvancedSearch where I should write folder in which I will search. I filtering sum folders like this:

    Outlook.OlDefaultFolders.olFolderDrafts
    Outlook.OlDefaultFolders.olFolderDeletedItems
    Outlook.OlDefaultFolders.olFolderOutbox
    Outlook.OlDefaultFolders.olFolderSyncIssues
    Outlook.OlDefaultFolders.olFolderCalendar

    and don't search in there (and don't search subfolders in there).

    On exchange account at some users I get some folder (or folders) where I can't search, I get "Operation failed exception". But in another folder from the same user all search fine.

    p.s.

    I use redemption library in my project, may be this library can help me to get folders available to search ?

    • Edited by Mickael-M-V Monday, October 14, 2013 7:22 PM
    Monday, October 14, 2013 7:20 PM
  • Can you identify which folder exactly causes the problem to manifest itself?

    If you want to search through all folders in a store, you really need to start with the root folder of the store and make sure SearchSunfolders parameter is true.

    If you need to exclude certain folders, you need to specify that in the search criteria through the PR_PARENT_ENTRYID (DASL name http://schemas.microsoft.com/mapi/proptag/0x0E090102) condition <> 'TheEntryIDValue'


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

    • Marked as answer by Mickael-M-V Thursday, October 17, 2013 5:20 AM
    Tuesday, October 15, 2013 1:06 AM
  • I need to load all items such as (MailItem,MeetingItem,ReportItem,AppointmentItem,TaskItem,ContactItem) for user outlook account. I collect all folders for this store and search in they.
    Tuesday, October 15, 2013 8:11 AM
  • May be I can't search with method AdvanceSearch in some folders classes (I mean folder Class property) ?
    Tuesday, October 15, 2013 9:29 AM
  • Ok. So have you tried my suggestion?

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

    Wednesday, October 16, 2013 6:48 PM