'GetExchangeUser() returns null when Outlook 2016 uses Cached Exchange Mode
Developing for: Outlook 2016 Add-In: VSTO (C#)
My company is running on O365 (Exchange) and I am developing an add-in which collects their exchange user information and does various things. However, it appears that when the Outlook Account Settings is configured with Cached Exchange Mode enabled the GetExchangeUser() returns null.
If I disable the clients Cached Exchange Mode everything works fine. However my company wants to keep this feature enabled.
My rough understanding is that GetExchangeUser() only works when connected to the Exchange Server. I suspect that the Cached mode causes this not to be the case all the time and therefore the method fails. So I'm wondering ..
- How can I force (temporarily) Outlook to connect to Exchange so that GetExchangeUser() works?
Are there any alternative ways of collecting the Exchange user information?
// Create a singleton of the Application instance. Outlook.Application app = new Outlook.Application(); // Get the current user object. Outlook.ExchangeUser currentUser = app.Session.CurrentUser.AddressEntry.GetExchangeUser(); // ***** currentUser == null when "Use Cached Exchange Mode" is enabled. // ***** currentUser == Outlook.ExchangeUser object when "Use Cached Exchange Mode" is disabled. // Set the form details. textBoxName.Text = currentUser.Name; textBoxEmployeeID.Text = currentUser.Alias;
I have tried a number of suggestions I've found online, none of them have worked. Such as ..
- Force a Offline Address book update (Doesn't work).
- Delete the old Offline Address Book then force an update (Doesn't work).
Solution 1:[1]
Keep in mind that ExchangeUser
object (returned from AddressEntry.GetExchangeUser()
) does not expose anything you cannot get from AddressEntry.PropertyAccessort.GetProperty()
.
Verify that the data is actually there - you can do that from OutlookSpy (I am its author): click Namespace button on the OutlookSpy ribbon. Expand CurrentUser property, expand AddressEntry, select MAPIOBJECT property, click "Browse". In the IMailUser window, do you see all the MAPI properties that you need? If you select a property, OutlookSpy will show its DASL name. You can use that DASL property name when calling AddressEntry.PropertyAccessort.GetProperty()
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ryan M |