Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Search for appointments with category "Holiday"
The following example shows you how to search for appointments belong to category "Holiday".
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[6]; propertyName[0] = AppointmentProperty.ContentClass; propertyName[1] = AppointmentProperty.StartDate; propertyName[2] = AppointmentProperty.EndDate; propertyName[3] = AppointmentProperty.Subject; propertyName[4] = AppointmentProperty.Body; propertyName[5] = new PropertyName("Keywords", "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/"); Select select = new Select(propertyName); From from = new From(myMailbox.Calendar); Where where = new Where(); Condition condition1 = new Condition(AppointmentProperty.ContentClass, Operator.Equals, ContentClassType.Appointment); Like like1 = new Like(propertyName[5], "Holiday"); where.Add(condition1); where.Add(LogicalOperator.AND); where.Add(like1); 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++) { //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); if (property[5] != null) { string[] keywords = ParseKeywords(property[5].Value); string keywordsLine = ""; for (int k = 0; k < keywords.Length; k++) { keywordsLine += keywords[k] + ","; } Console.WriteLine("Keywords=" + keywordsLine); } } Console.Read(); } private static string[] ParseKeywords(string input) { input = input.Replace("
", ","); input = input.Replace("
", ""); input = input.Replace("
", ""); input = input.Replace("
", ","); char[] commaSeparator = { ',' }; string[] output = input.Split(commaSeparator); return output; } } }
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(5) {} propertyName(0) = AppointmentProperty.ContentClass propertyName(1) = AppointmentProperty.StartDate propertyName(2) = AppointmentProperty.EndDate propertyName(3) = AppointmentProperty.Subject propertyName(4) = AppointmentProperty.Body propertyName(5) = New PropertyName("Keywords", "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/") Dim selectStatement As Independentsoft.Webdav.Exchange.Sql.Select = New Independentsoft.Webdav.Exchange.Sql.Select(propertyName) Dim from As From = New From(myMailbox.Calendar) Dim where As Where = New Where Dim condition1 As Condition = New Condition(AppointmentProperty.ContentClass, [Operator].Equals, ContentClassType.Appointment) Dim like1 As Independentsoft.Webdav.Exchange.Sql.Like = New Independentsoft.Webdav.Exchange.Sql.Like(propertyName(5), "Holiday") where.Add(condition1) where.Add(LogicalOperator.AND) where.Add(like1) 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 '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) If (Not appoitnmentProperty(5) Is Nothing) Then Dim keywords() As String = ParseKeywords(appoitnmentProperty(5).Value) Dim keywordsLine As String = "" Dim k As Integer For k = 0 To keywords.Length - 1 keywordsLine += keywords(k) + "," Next Console.WriteLine("Keywords=" + keywordsLine) End If Next Console.Read() End Sub Function ParseKeywords(ByVal input As String) As String() input = input.Replace("
", ",") input = input.Replace("
", "") input = input.Replace("
", "") input = input.Replace("
", ",") Dim commaSeparator() As Char = {","} Dim output() As String = input.Split(commaSeparator) ParseKeywords = output End Function End Module