none
Programmatically add folder takes long time RRS feed

  • Question

  • Hi,

    I am recursively adding inbox type folders but it takes very long time to add. How can I make it fast?

    My code is:

    rootFolder = Application.Session.DefaultStore.GetRootFolder() as Outlook.Folder;

    below line executes recursively and is the main culprit:

    Outlook.FolderChild = rootFolder.Folders.Add(Name, Outlook.OlDefaultFolders.olFolderInbox) asOutlook.Folder;

    Thank you.

    Thursday, March 13, 2014 6:25 AM

Answers

  • Yes, the RDO family of objects in Redemption can be used in a secondary thread in Outlook. On the main Outlook thread, read the value of the Namespace.MAPIOBJECT property and store it in a class variable. On the secondary thread, create an instance of the RDOSession object (that will ensure that the MAPI system is initialized on that thread) and set the RDOSession.MAPIOBJECT property (to ensure that both Redemption and Outlook are using the same MAPI session).


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

    Friday, March 14, 2014 1:23 PM

All replies

  • Hello Haris,

    A possible solution is to run another threads for creating required folders in the background. But Outlook uses single threaded apartments. So, you shouldn't use its objects, properties and methods in another threads. Instead, you may use a low level code (Extended MAPI) or any other wrappers around the Messaging API (for example, Redemption).

    Thursday, March 13, 2014 10:35 AM
  • How long does each call take? Are you using an Exchange store? Is it online or cached?


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

    Thursday, March 13, 2014 3:04 PM
  • Hello,

    It takes more than 3 seconds for a call. Which when multiplied by the number of calls becomes so annoying for the  user. Some times user have to wait a minute for this to work. Regarding your question about exchange store, I have no idea about what you are asking :) I am a newbie to this addin stuff. Need detailed help in this issue.

    Thanks in advance.

    Friday, March 14, 2014 5:13 AM
  • Thank you Eugene for your quick responce. Is there any way I can make it fast without using any external tool?
    Friday, March 14, 2014 5:15 AM
  • Hi Dmitry

    Does Redemption helps to solve the issue of using Outlook Object Model in a separate thread from an Add-In (.NET).?

    Thanks,

    Raghunathan S

    Friday, March 14, 2014 12:57 PM
  • Yes, the RDO family of objects in Redemption can be used in a secondary thread in Outlook. On the main Outlook thread, read the value of the Namespace.MAPIOBJECT property and store it in a class variable. On the secondary thread, create an instance of the RDOSession object (that will ensure that the MAPI system is initialized on that thread) and set the RDOSession.MAPIOBJECT property (to ensure that both Redemption and Outlook are using the same MAPI session).


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

    Friday, March 14, 2014 1:23 PM
  • Sure. You can use a low level API (Extended MAPI) on which all other external tools are based. Frankly speaking, Outlook as a big wrapper around the Messaging API [extended] too.

    Friday, March 14, 2014 3:30 PM
  • Raghunathan,

    To be precise, the ability is provided by Extended API. Redemption is just a wrapper around that API.

    Friday, March 14, 2014 3:33 PM