Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Search for appointments in public folder
The following example shows you how to search for appointments in public folder.
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); Resource resource = new Resource(session); string publicFolder = "https://myserver/public/Calendar"; PropertyName[] propertyName = new PropertyName[5]; propertyName[0] = AppointmentProperty.ContentClass; propertyName[1] = AppointmentProperty.StartDate; propertyName[2] = AppointmentProperty.EndDate; propertyName[3] = AppointmentProperty.Subject; propertyName[4] = AppointmentProperty.Body; Select select = new Select(propertyName); From from = new From(publicFolder); Where where = new Where(); Condition condition1 = new Condition(AppointmentProperty.ContentClass, Operator.Equals, ContentClassType.Appointment); where.Add(condition1); SqlQuery sqlQuery = new SqlQuery(select, from, where); MultiStatus multiStatus = resource.Search(publicFolder, sqlQuery); SearchResult searchResult = new SearchResult(multiStatus, propertyName); SearchResultRecord[] allRecords = searchResult.Record; for (int i = 0; i < allRecords.Length; i++) { //appointment URL Console.WriteLine("Appointment URL=" + allRecords[i].Address); //appoitnment's properties Property[] property = allRecords[i].Property; Console.WriteLine("ContentClass=" + property[0].Value); Console.WriteLine("StartDate=" + property[1].Value); Console.WriteLine("EndDate=" + property[2].Value); Console.WriteLine("Subject=" + property[3].Value); Console.WriteLine("Body=" + property[4].Value); } 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) Dim resource As Resource = New Resource(session) Dim publicFolder As String = "https://myserver/public/Calendar" Dim propertyName() As PropertyName = New PropertyName(4) {} propertyName(0) = AppointmentProperty.ContentClass propertyName(1) = AppointmentProperty.StartDate propertyName(2) = AppointmentProperty.EndDate propertyName(3) = AppointmentProperty.Subject propertyName(4) = AppointmentProperty.Body Dim selectStatement As Independentsoft.Webdav.Exchange.Sql.Select = New Independentsoft.Webdav.Exchange.Sql.Select(propertyName) Dim from As From = New From(publicFolder) Dim where As Where = New Where Dim condition1 As Condition = New Condition(AppointmentProperty.ContentClass, [Operator].Equals, ContentClassType.Appointment) where.Add(condition1) Dim sqlQuery As SqlQuery = New SqlQuery(selectStatement, from, where) Dim multiStatus As MultiStatus = resource.Search(publicFolder, 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 'appointment URL Console.WriteLine("Appointment URL=" + allRecords(i).Address) 'appoitnment's properties Dim appoitnmentProperty() As Independentsoft.Webdav.Exchange.Property = allRecords(i).Property Console.WriteLine("ContentClass=" + appoitnmentProperty(0).Value) Console.WriteLine("StartDate=" + appoitnmentProperty(1).Value) Console.WriteLine("EndDate=" + appoitnmentProperty(2).Value) Console.WriteLine("Subject=" + appoitnmentProperty(3).Value) Console.WriteLine("Body=" + appoitnmentProperty(4).Value) Next Console.Read() End Sub End Module