Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Find contacts by name
The following example shows you how to find contacts by name.
C# example
using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver/ews/Exchange.asmx", credential); try { IsEqualTo restriction = new IsEqualTo(ContactPropertyPath.GivenName, "Michael"); FindItemResponse response = service.FindItem(StandardFolder.Contacts, ContactPropertyPath.AllPropertyPaths, restriction); for (int i = 0; i < response.Items.Count; i++) { if (response.Items[i] is Contact) { Contact contact = (Contact)response.Items[i]; Console.WriteLine("GivenName = " + contact.GivenName); Console.WriteLine("Surname = " + contact.Surname); Console.WriteLine("CompanyName = " + contact.CompanyName); Console.WriteLine("BusinessAddress = " + contact.BusinessAddress); Console.WriteLine("BusinessPhone = " + contact.BusinessPhone); Console.WriteLine("Email1DisplayName = " + contact.Email1DisplayName); Console.WriteLine("Email1Address = " + contact.Email1Address); Console.WriteLine("----------------------------------------------------------------"); } } Console.Read(); } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Exchange Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim service As New Service("https://myserver/ews/Exchange.asmx", credential) Try Dim restriction As New IsEqualTo(ContactPropertyPath.GivenName, "Michael") Dim response As FindItemResponse = service.FindItem(StandardFolder.Contacts, ContactPropertyPath.AllPropertyPaths, restriction) For i As Integer = 0 To response.Items.Count - 1 If TypeOf response.Items(i) Is Contact Then Dim contact As Contact = DirectCast(response.Items(i), Contact) Console.WriteLine("GivenName = " + contact.GivenName) Console.WriteLine("Surname = " + contact.Surname) Console.WriteLine("CompanyName = " + contact.CompanyName) Console.WriteLine("BusinessAddress = " + contact.BusinessAddress) Console.WriteLine("BusinessPhone = " + contact.BusinessPhone) Console.WriteLine("Email1DisplayName = " + contact.Email1DisplayName) Console.WriteLine("Email1Address = " + contact.Email1Address) Console.WriteLine("----------------------------------------------------------------") End If Next Console.Read() Catch ex As ServiceRequestException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.XmlMessage) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*