Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

How to retrieve CustomAttribute/Extended Properties of a Exchange user who is logged in Outlook

$
0
0

I am trying to fetch extended properties for a exchange user who is logged in Outlook.

Here is my code snippet,but the extended-properties collection has no results.

private string fetchDetailsFromAD()
        {
            //get currently logged in user in OUTLOOK
            string email_from=null;
            Outlook.AddressEntry currentUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            foreach (Microsoft.Office.Interop.Outlook.Account acct in Globals.ThisAddIn.Application.Session.Accounts)
            {
                if (acct.CurrentUser.Address == currentUser.Address)
                {
                    email_from = acct.SmtpAddress;
                    break;
                }
            }
            service.Credentials = new NetworkCredential("han@zepto.com.my", "abcd1234!");

            // Look up the user's EWS endpoint by using Autodiscover.
            service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

            Contact contact = null;
            try
            {
                NameResolutionCollection allContacts = service.ResolveName(email_from, ResolveNameSearchLocation.DirectoryOnly, true);

                if (allContacts.Any())
                {
                    contact = allContacts[0].Contact;
                }
                       }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error in GetContactInfo(): "+ ex.Message);
                //throw;
                return "";
            }


            return contact.JobTitle;
        }

So I have Contact object which has ExtendedProperties,but it is an empty collection.

Please let me know how could I fetch them.

For this user I have set CustomAttrribute10 as per attached image.


Point5Nyble


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>