0
votes

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).
1
Are you sure app.Session.CurrentUser.AddressEntry == "EX" when you get back null?Dmitry Streblechenko
@DmitryStreblechenko Absolutely. Session.CurrentUser.AddressEntry definitely equals "EX".Vidarious

1 Answers

2
votes

Keep in mind that ExchageUser object (returned from AddressEntry.GetExchageUser()) does not expose anything you cannot get from AddressEntry.PropertyAccessort.GetProperty().

Verify that the data is actually there - you can do that from OutlookSpy: 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().