Advanced scenarios for addins hosted by Outlook may require you to know whether the user is currently connected to Exchange using cached or online mode. Outlook behaves very differently when it runs in cached mode as opposed to online mode, and there are many MAPI properties whose availability depends on this as well. The connection mode also totally changes our frame of reference; when we are in cached mode, we are dealing with data that is not necessarily sync’d with the server.

Checking your connection mode is simple enough. The Outlook Object Model makes this very easy by exposing the ExchangeConnectionMode property on any NameSpace instance. This property makes very clear whether we are online mode or not. Relying on this property alone, however, is not a good idea, as it only is an absolute authority as far as the user’s personal stores are concerned. It is very possible for the ExchangeConnectionMode property to indicate that you are using cached mode, and at the same time the Outlook client is accessing a store using online mode.

Read on for details and how to implement a thorough connection mode checking solution.

First off, a little history.

Prior to Outlook 2003, all connections made to Exchange were done in online mode. When Outlook 2003 emerged from the nether, it offered a new way of connecting: Exchange Cached Mode. This allowed a user to connect to their personal mailbox, calendar, and everything else in their inbox in a way that made use of a local storage subsystem instead of conducting everything over the network.

While this was great, any shared stores (i.e. shared calendar you delegate for) were still accessed via online mode.

When Outlook 2007 came out, the ability to access shared stores via cached mode was finally introduced. By default, Exchange accounts in Outlook 2007 and 2010 are set up so that you access your personal and shared stores using cached mode.

Outlook 2007 also introduced a new option that specifically allowed you to turn off cached mode for shared folders only: “Download Shared Folders”. This option is available in the Advance section of the profile’s Exchange account settings. This option is also included in Outlook 2010.

That being said, if cached mode is enabled and the “Download Shared Folders” option is unchecked, you will be accessing all shared stores via classic online mode. Unfortunately, even though you are accessing via online mode, the ExchangeConnectionMode property will still reflect that you are connected using cached mode. If you have any code that needs to operate differently in online vs. cached mode, then it will fail in the event that a shared folder is accessed in this manner.

So it would appear that the solution here is to not only check the ExchangeConnectionMode property, but to also check whether or not “Download Shared Folders” is checked.

Unfortunately for you, there is no property exposed in the Outlook Object Model that tells you the value for this setting. As far as I’m aware, there is no documentation whatsoever on where this setting is actually stored.

After much investigating, I finally discovered a way to read the setting for this value.

The “Download Shared Folders” setting is actually stored in the user’s profile, specifically in their profile’s PR_PROFILE_CONFIG_FLAGS. Please read my article Outlook Profile Management II in order to learn how to retrieve these connection flags (especially if you are using Outlook 2010, as this gets a bit tricky).

After much poking around, I managed to figure out that the value for the “Download Shared Folders” setting is reflected in the 11th bit of the PR_PROFILE_CONFIG_FLAGS. So, continuing the code snippet from the article I linked, we can check if the “Download Shared Folders” option is set by doing the following (untested):

IProfSect primarySection = primaryProvider.ProfSect;

object configFlags = primarySection.Item[0x66010003]

if (null != configFlags)
{
  int numConfigFlags = Convert.ToInt32(configFlags, CultureInfo.InvariantCulture);

  if (numConfigFlags & 0x800 == 0)
  {
  // User has "Download Shared Folders" unchecked.
  }
  else
  {
  // User has "Download Shared Folders" checked.
  }
}

The above snippet will let you change your behavior based on whether the “Download Shared Folders” option is checked or not. An important thing to remember is that the “Download Shared Folders” setting can be completely ignored if the ExchangeConnectionMode indicates that the user is connected in online mode. It is impossible for the user to be connected to personal stores via online mode and shared stores via cached (as far as I know).

Matt Weber

I'm the founder of Bad Echo LLC, which offers consulting services to clients who need an expert in C#, WPF, Outlook, and other advanced .NET related areas. I enjoy well-designed code, independent thought, and the application of rationality in general. You can reach me at matt@badecho.com.

  One Response to “Detecting if ‘Download Shared Folders’ is Checked in Outlook”

  1. The sample code in this article looks exactly like what I need to determine if a given user has download shared folders checked.
    I haven’t worked with this api before and can’t seem to find what component I need to referent in order to view the IProfSect interface. Do you have the “other” code that goes with this snippit?

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
   
© 2012-2013 Matt Weber. All Rights Reserved. Terms of Use.