3
votes

I have a VSTO Outlook 2007 Add-in. I have to check whether Outlook is Offline / Online with exchange server. I am using the code as below:

 NameSpace ns = Application.GetNamespace("MAPI");
 MAPIFolder publicFolder = ns.GetDefaultFolder(OlDefaultFolders.olPublicFoldersAllPublicFolders);
    if (publicFolder == null)
       {
          offline = true;//Flag is set to tell it is offline
       }

Earlier this code was working fine. But all of a sudden the line to get public folders started returning null even when Outlook is online.

I came to know that public folders have been removed from the exchange server that's why it is returning null.

Can anyone please tell me any alternative & standard way of checking whether Outlook is online with exchange server?

Thanks & best regards, Nadeem Ullah

1

1 Answers

3
votes

Take a look at the ExchangeConnectionMode property, it returns the Exchange status.


To reply @Clint, in the comments below, This is a small decade since I answered the question, I don't have the environment installed anymore so here's some (completely untested) code that might or might not work, if not I hope it will provide a hint in the right direction.

Add the following to a action e.g. a button, that you can invoke after the initialization is done.

Outlook.NameSpace outlookSession = null;
outlookSession = MyAddin.CurrentInstance.OutlookApp.Session;
Debug.WriteLine(outlookSession.ExchangeConnectionMode);

This should return something like: Outlook.OlExchangeConnectionMode.olOnline that you will then have to convert to the format or action you would like to have / perform.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._account.exchangeconnectionmode.aspx