Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Display mailbox folder tree
The following example shows you how to use recursive search to display mailbox folder structure.
C# example
using System; using System.Net; using Independentsoft.Webdav.Exchange; using Independentsoft.Webdav.Exchange.ContentClass; using Independentsoft.Webdav.Exchange.Properties; using Independentsoft.Webdav.Exchange.Sql; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); WebdavSession session = new WebdavSession(credential); session.UserMailbox = "https://myserver/exchange/emailaddress"; Resource resource = new Resource(session); Mailbox myMailbox = resource.Mailbox; PropertyName[] propertyName = new PropertyName[1]; propertyName[0] = FolderProperty.IsFolder; Select select = new Select(propertyName); From from = new From(myMailbox.Root, Scope.Deep); Where where = new Where(); Condition condition1 = new Condition(FolderProperty.IsFolder, Operator.Equals, true); where.Add(condition1); SqlQuery sqlQuery = new SqlQuery(select, from, where); MultiStatus multiStatus = resource.Search(sqlQuery); SearchResult searchResult = new SearchResult(multiStatus, propertyName); SearchResultRecord[] allRecords = searchResult.Record; for (int i = 0; i < allRecords.Length; i++) { //folder URL string folderUrl = allRecords[i].Address; Console.WriteLine("folderUrl=" + folderUrl); } Console.Read(); } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Webdav.Exchange Imports Independentsoft.Webdav.Exchange.ContentClass Imports Independentsoft.Webdav.Exchange.Properties Imports Independentsoft.Webdav.Exchange.Sql Module Module1 Sub Main(ByVal args() As String) Dim credential As NetworkCredential = New NetworkCredential("username", "password") Dim session As WebdavSession = New WebdavSession(credential) session.UserMailbox = "https://myserver/exchange/emailaddress" Dim resource As Resource = New Resource(session) Dim myMailbox As Mailbox = resource.Mailbox Dim propertyName() As PropertyName = New PropertyName(0) {} propertyName(0) = FolderProperty.IsFolder Dim selectStatement As Independentsoft.Webdav.Exchange.Sql.Select = New Independentsoft.Webdav.Exchange.Sql.Select(propertyName) Dim from As From = New From(myMailbox.Root, Scope.Deep) Dim where As Where = New Where Dim condition1 As Condition = New Condition(FolderProperty.IsFolder, [Operator].Equals, True) where.Add(condition1) Dim sqlQuery As SqlQuery = New SqlQuery(selectStatement, from, where) Dim multiStatus As MultiStatus = resource.Search(sqlQuery) Dim searchResult As SearchResult = New SearchResult(multiStatus, propertyName) Dim allRecords() As SearchResultRecord = searchResult.Record Dim i As Integer For i = 0 To allRecords.Length - 1 'folder URL Dim folderUrl As String = allRecords(i).Address Console.WriteLine("folderUrl=" & folderUrl) Next Console.Read() End Sub End Module