How to Detect if Outlook is Offline

Add-in Express™ Support Service
That's what is more important than anything else

How to Detect if Outlook is Offline
 
Barclay Berger




Posts: 16
Joined: 2009-01-15
I want to check if outlook is offline when outlook opens and when they click a button on my addin, too often I have users who bring their notebooks home and open outlook when offline and don't know how to get it back online even after I've told them 100 times. Is there way to check this, I found something about seeing if can open public folders but the example I found I could not get to work in c#. Thanks
Posted 09 Feb, 2010 16:27:53 Top
Andrei Smolin


Add-in Express team


Posts: 15365
Joined: 2006-05-11
Hi Barclay,

Please see NameSpace.Offline (Outlook 2002-2007) and NameSpace.ExchangeConnectionMode (Outlook 2003-2007).

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Feb, 2010 08:09:30 Top
Christopher Cardinal




Posts: 133
Joined: 2005-05-17
is this an ms exchange environment? if so, the outlook namespace object has the ExchangeConnectionMode property - this prop may have the value of Disconnected or Offline (see enum OlExchangeConnectionMode).
Posted 10 Feb, 2010 08:11:27 Top
Christopher Cardinal




Posts: 133
Joined: 2005-05-17
argh - Andrei beat me to it...

the forum is cachng posts again!
Posted 10 Feb, 2010 08:12:06 Top
Barclay Berger




Posts: 16
Joined: 2009-01-15
I was doing it this way which is shorter but have switched to new suggestion but not sure which is better??

Old Way:
Outlook.MAPIFolder publicFolders = (Outlook.MAPIFolder)OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
if (publicFolders == null)
{
MessageBox.Show("2You are not connected to the Exchange Server, please make sure you are working online" + "\n" + "Check lower right hand corner of Outlook for your connection status", "Outlook is Offline", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}

New Way:
switch (OutlookApp.Session.ExchangeConnectionMode)
{
case Microsoft.Office.Interop.Outlook.OlExchangeConnectionMode.olNoExchange:
{
MessageBox.Show("You are not connected to the Exchange Server, please make sure you are working online" + "\n" + "Check lower right hand corner of Outlook for your connection status", "Outlook is Offline", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
case Microsoft.Office.Interop.Outlook.OlExchangeConnectionMode.olCachedOffline:
{
MessageBox.Show("You are not connected to the Exchange Server, please make sure you are working online" + "\n" + "Check lower right hand corner of Outlook for your connection status", "Outlook is Offline", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
case Microsoft.Office.Interop.Outlook.OlExchangeConnectionMode.olOffline:
{
MessageBox.Show("You are not connected to the Exchange Server, please make sure you are working online" + "\n" + "Check lower right hand corner of Outlook for your connection status", "Outlook is Offline", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
}
Posted 10 Feb, 2010 10:49:32 Top
Andrei Smolin


Add-in Express team


Posts: 15365
Joined: 2006-05-11
Hi Barclay,

The second way is better as it will not produce any unwanted results. The unwanted results might be (requires verification): a login dialog if your old code initiates connecting to Exchange and a delay when accessing Public Folders on a dial-up connection.

Hi Christopher,

This wasn't a case of caching as you posted in just two minutes after me. :)

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Feb, 2010 11:14:11 Top
Barclay Berger




Posts: 16
Joined: 2009-01-15
thanks, that makes sense. Appreciate the help
Posted 10 Feb, 2010 16:19:47 Top