Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> List folders
The following example shows you how to list all mailbox folders.
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 { FindFolderResponse findFolderResponse1 = service.FindFolder(StandardFolder.MailboxRoot); FindFolderResponse findFolderResponse2 = service.FindFolder(StandardFolder.PublicFoldersRoot); //List first level mailbox folders for (int i = 0; i < findFolderResponse1.Folders.Count; i++) { Console.WriteLine(findFolderResponse1.Folders[i].DisplayName); Console.WriteLine(findFolderResponse1.Folders[i].FolderId); } Console.WriteLine("-------------------------------------------------------------------"); //List first level public folders for (int i = 0; i < findFolderResponse2.Folders.Count; i++) { Console.WriteLine(findFolderResponse2.Folders[i].DisplayName); Console.WriteLine(findFolderResponse2.Folders[i].FolderId); } 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 findFolderResponse1 As FindFolderResponse = service.FindFolder(StandardFolder.MailboxRoot) Dim findFolderResponse2 As FindFolderResponse = service.FindFolder(StandardFolder.PublicFoldersRoot) 'List first level mailbox folders For i As Integer = 0 To findFolderResponse1.Folders.Count - 1 Console.WriteLine(findFolderResponse1.Folders(i).DisplayName) Console.WriteLine(findFolderResponse1.Folders(i).FolderId) Next Console.WriteLine("-------------------------------------------------------------------") 'List first level public folders For i As Integer = 0 To findFolderResponse2.Folders.Count - 1 Console.WriteLine(findFolderResponse2.Folders(i).DisplayName) Console.WriteLine(findFolderResponse2.Folders(i).FolderId) 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*