开发者

vsto outlook add-in: How to check whether Outlook is online with exchange server

开发者 https://www.devze.com 2023-03-14 07:08 出处:网络
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:

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)
       {
      开发者_JAVA技巧    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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消