Aspose.Email.Examples.CSharp.Email.Exchange.GetContactsExtendedProperties.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {
            try
            {
                // ExStart:GetContactsExtendedProperties
                IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

                // The required extended properties must be added in order to create or read them from the Exchange Server
                string[] extraFields = new string[] { "User Field 1", "User Field 2", "User Field 3", "User Field 4" };
                foreach (string extraField in extraFields)
                    client.ContactExtendedPropertiesDefinition.Add(extraField);

                // Create a test contact on the Exchange Server
                Contact contact = new Contact();
                contact.DisplayName = "EMAILNET-38433 - " + Guid.NewGuid().ToString();
                foreach (string extraField in extraFields)
                    contact.ExtendedProperties.Add(extraField, extraField);

                string contactId = client.CreateContact(contact);

                // retrieve the contact back from the server after some time
                Thread.Sleep(5000);
                contact = client.GetContact(contactId);

                // Parse the extended properties of contact 
                foreach (string extraField in extraFields)
                    if (contact.ExtendedProperties.ContainsKey(extraField))
                        Console.WriteLine(contact.ExtendedProperties[extraField].ToString());
                // ExEnd:GetContactsExtendedProperties
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                throw;
            }
        }
    }
GetContactsExtendedProperties