none
How to access required sub folder directly over thousands of sub-folders? RRS feed

  • Question

  • Hi,


    I'm working on project, basically which fetches mails from outlook sub-folders and will do some business required things.


    Shared mailbox (say Public folders) having a deeply nested sub-folders, mailbox containing more than two thousand sub-folders. Here I'm able to find required sub-folder by navigate through all. Everytime its taking almost 5-10 mins to find the one which I want.


    Is there any way to access (in vb.net or c#) required sub-folder directly or if someone having piece of code to access share with please.


    FYI, I'm having full sub-folder path with me and it won't get changed also.

    Thanks,

    A.

    Friday, November 25, 2016 7:02 PM

Answers

  • Hello Adithya,

    The best solution is to move your long-running code to a secondary thread. But Outlook doesn't allows to deal with its OOM from secondary threads, so the only possible solution is to use Extended MAPI or any other third-party wrappers (for example, Redemption).

    Also you may consider using EWS, see EWS Managed API, EWS, and web services in Exchange for more information. 

    Do you have the cached mode enabled in Outlook?

    Go to Account Settings in Outlook, E-Mail Tab click Change.  Select "Use Cached Exchange Mode" then select More Settings.  Click the Advanced Tab check "Download Public Folder Favorites", press OK then next, then Finish.  Close Outlook and reopen wait folders to replicate.  Add the Public Folders of your choice to your Favorites list by right clicking and Add to Favorites.  They will cache the data locally and the problem is solved.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by Adithya D Tuesday, November 29, 2016 3:35 AM
    Saturday, November 26, 2016 12:16 PM

All replies

  • Hello Adithya,

    The best solution is to move your long-running code to a secondary thread. But Outlook doesn't allows to deal with its OOM from secondary threads, so the only possible solution is to use Extended MAPI or any other third-party wrappers (for example, Redemption).

    Also you may consider using EWS, see EWS Managed API, EWS, and web services in Exchange for more information. 

    Do you have the cached mode enabled in Outlook?

    Go to Account Settings in Outlook, E-Mail Tab click Change.  Select "Use Cached Exchange Mode" then select More Settings.  Click the Advanced Tab check "Download Public Folder Favorites", press OK then next, then Finish.  Close Outlook and reopen wait folders to replicate.  Add the Public Folders of your choice to your Favorites list by right clicking and Add to Favorites.  They will cache the data locally and the problem is solved.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by Adithya D Tuesday, November 29, 2016 3:35 AM
    Saturday, November 26, 2016 12:16 PM
  • Hi Adithya D,

    you had asked for demo sample codes.

    you can refer the code and links mentioned below.

    using Outlook = Microsoft.Office.Interop.Outlook;
    
    private void GetRSSFeeds()
    {
        Outlook.Folder folder =
            Application.Session.GetDefaultFolder(
            Outlook.OlDefaultFolders.olFolderRssFeeds)
            as Outlook.Folder;
        if (folder != null)
        {
            if (folder.Folders.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Outlook.Folder subfolder
                    in folder.Folders)
                {
                    sb.AppendLine(subfolder.Name);
                }
                MessageBox.Show(sb.ToString(),
                    "RSS Feeds",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
        }
    }
    
    

    Reference:

    How to: Get a Default Folder and Enumerate Its Subfolders

    using Outlook = Microsoft.Office.Interop.Outlook;
    
    private void EnumerateFoldersInDefaultStore()
    {
        Outlook.Folder root =
            Application.Session.
            DefaultStore.GetRootFolder() as Outlook.Folder;
        EnumerateFolders(root);
    }
    
    // Uses recursion to enumerate Outlook subfolders.
    private void EnumerateFolders(Outlook.Folder folder)
    {
        Outlook.Folders childFolders =
            folder.Folders;
        if (childFolders.Count > 0)
        {
            foreach (Outlook.Folder childFolder in childFolders)
            {
                // Write the folder path.
                Debug.WriteLine(childFolder.FolderPath);
                // Call EnumerateFolders using childFolder.
                EnumerateFolders(childFolder);
            }
        }
    }               
    
    
    

    Reference:

    How to: Enumerate Folders

     Outlook.Folders subFolders = inboxfolder.Folders[1].Folders;
                    for (int h = 0; h < subFolders.Count; h++)
                    {
                        Items itms = subFolders[h + 1].Items;
                            for (int j = 1; j < itms.Count; j++)
                            {
                                if (itms[j] is MailItem)
                                {
                                    Outlook.MailItem mi = (MailItem)itms[j];
                                    MessageBox.Show(mi.Body);
                                }
                            }
                    }

    Reference:

    Accessing Outlook sub folders via c#

    public void GetFoldersInFolder(OutLook.MAPIFolder folder)
       {
         foreach (OutLook.MAPIFolder subFolder in folder.Folders)
               {
                   if (!nbFolder.Items.Contains(subFolder.Name))
                   {
                       nbFolder.Items.Add(subFolder.Name);
                       GetFoldersInFolder(subFolder);
                   }
               }
        }
    

    Reference:

    Navigate in outlook Inbox sub folders

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 28, 2016 12:14 AM
    Moderator
  • Thanks Eugne Astafiev

    Thanks, A.

    Tuesday, November 29, 2016 3:37 AM
  • Thanks for your answer

    Thanks, A.

    Tuesday, November 29, 2016 3:37 AM