GetExchangeUser() returns null when Outlook 2016 uses Cached Exchange Mode

◇◆丶佛笑我妖孽 提交于 2020-12-08 01:56:53

问题


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:


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().



来源:https://stackoverflow.com/questions/55536504/getexchangeuser-returns-null-when-outlook-2016-uses-cached-exchange-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!