none
How to use an Interface in MS Outlook ThisAddin RRS feed

  • Question

  • I have an interface IADCurrentNameLookup and the method is GetUserFromAD. I implemented it in a class called ImplementGetUserFromAD. In my program I have a method ThisAddin_Startup(object sender, System.EventArgs e). I now want to call the GetUserFromAD in my program...how do I call it?

    • Moved by CoolDadTx Tuesday, August 2, 2016 6:10 PM Office related
    Tuesday, August 2, 2016 5:10 PM

Answers

  • Assuming you have a class that implements that interface then you can simply create an instance of the your class and call the method.

    var impl = new ImplementGetUserFromAD();
    impl.GetUserFromAD();

    However I suspect that the issue here isn't calling the method but implementing it. I suspect you created this interface and your base implementation because someone told you to do that. It looks like all you really probably want to do is get the current user from AD. To do that you don't need to implement any interfaces or really do much of anything as Outlook already has the current user information.

    Please clarify what you are trying to do.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Tuesday, August 2, 2016 6:10 PM
  • Hello,

    What is your final goal? Why do you need to use the IADCurrentNameLookup interface in the Startup event handler?

    The AddressEntry class from the Outlook object model provides the GetExchangeUser method which returns an ExchangeUser object that represents the AddressEntry if the AddressEntry belongs to an Exchange AddressList object such as the Global Address List (GAL) and corresponds to an Exchange user.

    Sub DemoAE()  
     Dim colAL As Outlook.AddressLists  
     Dim oAL As Outlook.AddressList  
     Dim colAE As Outlook.AddressEntries  
     Dim oAE As Outlook.AddressEntry  
     Dim oExUser As Outlook.ExchangeUser  
     Set colAL = Application.Session.AddressLists  
     For Each oAL In colAL  
     'Address list is an Exchange Global Address List  
     If oAL.AddressListType = olExchangeGlobalAddressList Then  
     Set colAE = oAL.AddressEntries  
     For Each oAE In colAE  
     If oAE.AddressEntryUserType = _  
     olExchangeUserAddressEntry _  
     Or oAE.AddressEntryUserType = _  
     olExchangeRemoteUserAddressEntry Then  
     Set oExUser = oAE.GetExchangeUser  
     Debug.Print (oExUser.JobTitle)  
     Debug.Print (oExUser.OfficeLocation)  
     Debug.Print (oExUser.BusinessTelephoneNumber)  
     End If  
     Next  
     End If  
     Next  
    End Sub 


    [custom.development]


    Tuesday, August 2, 2016 8:15 PM

All replies

  • Assuming you have a class that implements that interface then you can simply create an instance of the your class and call the method.

    var impl = new ImplementGetUserFromAD();
    impl.GetUserFromAD();

    However I suspect that the issue here isn't calling the method but implementing it. I suspect you created this interface and your base implementation because someone told you to do that. It looks like all you really probably want to do is get the current user from AD. To do that you don't need to implement any interfaces or really do much of anything as Outlook already has the current user information.

    Please clarify what you are trying to do.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Tuesday, August 2, 2016 6:10 PM
  • Hello,

    What is your final goal? Why do you need to use the IADCurrentNameLookup interface in the Startup event handler?

    The AddressEntry class from the Outlook object model provides the GetExchangeUser method which returns an ExchangeUser object that represents the AddressEntry if the AddressEntry belongs to an Exchange AddressList object such as the Global Address List (GAL) and corresponds to an Exchange user.

    Sub DemoAE()  
     Dim colAL As Outlook.AddressLists  
     Dim oAL As Outlook.AddressList  
     Dim colAE As Outlook.AddressEntries  
     Dim oAE As Outlook.AddressEntry  
     Dim oExUser As Outlook.ExchangeUser  
     Set colAL = Application.Session.AddressLists  
     For Each oAL In colAL  
     'Address list is an Exchange Global Address List  
     If oAL.AddressListType = olExchangeGlobalAddressList Then  
     Set colAE = oAL.AddressEntries  
     For Each oAE In colAE  
     If oAE.AddressEntryUserType = _  
     olExchangeUserAddressEntry _  
     Or oAE.AddressEntryUserType = _  
     olExchangeRemoteUserAddressEntry Then  
     Set oExUser = oAE.GetExchangeUser  
     Debug.Print (oExUser.JobTitle)  
     Debug.Print (oExUser.OfficeLocation)  
     Debug.Print (oExUser.BusinessTelephoneNumber)  
     End If  
     Next  
     End If  
     Next  
    End Sub 


    [custom.development]


    Tuesday, August 2, 2016 8:15 PM