Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Display public folder tree
The following example shows you how to use recursive search to display public folders structure.
C# example
using System; using System.Net; using System.Collections; using Independentsoft.Webdav.Exchange; using Independentsoft.Webdav.Exchange.Sql; using Independentsoft.Webdav.Exchange.Properties; namespace Sample { class Program { private static Resource resource = null; private static ArrayList folders = new ArrayList(); static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); WebdavSession session = new WebdavSession(credential); resource = new Resource(session); SearchPublicFolder("https://myserver/public"); for (int i = 0; i < folders.Count; i++) { Console.WriteLine(folders[i]); } Console.Read(); } public static void SearchPublicFolder(string folderUrl) { PropertyName[] propertyName = new PropertyName[2]; propertyName[0] = FolderProperty.IsFolder; propertyName[1] = FolderProperty.HasSubfolders; Select select = new Select(propertyName); From from = new From(folderUrl); 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(folderUrl, sqlQuery); SearchResult searchResult = new SearchResult(multiStatus, propertyName); SearchResultRecord[] allRecords = searchResult.Record; for (int i = 0; i < allRecords.Length; i++) { string url = allRecords[i].Address; folders.Add(url); Property[] properties = allRecords[i].Property; Property hasSubFolder = properties[1]; if (hasSubFolder.Value == "1") { SearchPublicFolder(url); } } } } }
VB example
Imports System Imports System.Net Imports System.Collections Imports Independentsoft.Webdav.Exchange Imports Independentsoft.Webdav.Exchange.Sql Imports Independentsoft.Webdav.Exchange.Properties Module Module1 Private resource As Resource = Nothing Private folders As New ArrayList() Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim session As New WebdavSession(credential) resource = New Resource(session) SearchPublicFolder("https://myserver/public") For i As Integer = 0 To folders.Count - 1 Console.WriteLine(folders(i)) Next Console.Read() End Sub Public Sub SearchPublicFolder(ByVal folderUrl As String) Dim propertyName As PropertyName() = New PropertyName(1) {} propertyName(0) = FolderProperty.IsFolder propertyName(1) = FolderProperty.HasSubfolders Dim [select] As New [Select](propertyName) Dim from As New From(folderUrl) Dim where As New Where() Dim condition1 As New Condition(FolderProperty.IsFolder, [Operator].Equals, True) where.Add(condition1) Dim sqlQuery As New SqlQuery([select], from, where) Dim multiStatus As MultiStatus = resource.Search(folderUrl, sqlQuery) Dim searchResult As New SearchResult(multiStatus, propertyName) Dim allRecords As SearchResultRecord() = searchResult.Record For i As Integer = 0 To allRecords.Length - 1 Dim url As String = allRecords(i).Address folders.Add(url) Dim properties As [Property]() = allRecords(i).[Property] Dim hasSubFolder As [Property] = properties(1) If hasSubFolder.Value = "1" Then SearchPublicFolder(url) End If Next End Sub End Module