Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Expand distribution list
The following example shows you how to get members of a distribution list.
C# example
using System; using System.Net; using System.Collections.Generic; 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.ItemClass, ItemClass.DistributionList); FindItemResponse response = service.FindItem(StandardFolder.Contacts, restriction); for (int i = 0; i < response.Items.Count; i++) { ItemId itemId = response.Items[i].ItemId; ExpandDistributionListResponse listResponse = service.ExpandDistributionList(itemId); IList
mailboxes = listResponse.Mailboxes; for (int j = 0; j < mailboxes.Count; j++) { Console.WriteLine("Member = " + mailboxes[j].EmailAddress); } 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 System.Collections.Generic 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.ItemClass, ItemClass.DistributionList) Dim response As FindItemResponse = service.FindItem(StandardFolder.Contacts, restriction) For i As Integer = 0 To response.Items.Count - 1 Dim itemId As ItemId = response.Items(i).ItemId Dim listResponse As ExpandDistributionListResponse = service.ExpandDistributionList(itemId) Dim mailboxes As IList(Of Mailbox) = listResponse.Mailboxes For j As Integer = 0 To mailboxes.Count - 1 Console.WriteLine("Member = " + mailboxes(j).EmailAddress) Next Console.WriteLine("---------------------------------------------------------------") 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*