Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
WebDAV .NET for Exchange
>
Tutorial
> Search for tasks
The following example shows you how to search for completed tasks.
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[7]; propertyName[0] = TaskProperty.ContentClass; propertyName[1] = TaskProperty.Subject; propertyName[2] = TaskProperty.Body; propertyName[3] = TaskProperty.StartDate; propertyName[4] = TaskProperty.DueDate; propertyName[5] = TaskProperty.PercentComplete; propertyName[6] = TaskProperty.IsComplete; Select select = new Select(propertyName); From from = new From(myMailbox.Tasks); Where where = new Where(); Condition condition1 = new Condition(TaskProperty.ContentClass, Operator.Equals, ContentClassType.Task); Condition condition2 = new Condition(new Cast(TaskProperty.IsComplete, "boolean"), Operator.Equals, "true"); where.Add(condition1); where.Add(LogicalOperator.AND); where.Add(condition2); 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++) { //task's URL string taskUrl = allRecords[i].Address; Console.WriteLine("taskUrl=" + taskUrl); //task's properties Property[] property = allRecords[i].Property; Console.WriteLine("Subject=" + property[1].Value); Console.WriteLine("Body=" + property[2].Value); Console.WriteLine("StartDate=" + property[3].Value); Console.WriteLine("EndtDate=" + property[4].Value); Console.WriteLine("PercentComplete=" + property[5].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) 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(6) {} propertyName(0) = TaskProperty.ContentClass propertyName(1) = TaskProperty.Subject propertyName(2) = TaskProperty.Body propertyName(3) = TaskProperty.StartDate propertyName(4) = TaskProperty.DueDate propertyName(5) = TaskProperty.PercentComplete propertyName(6) = TaskProperty.IsComplete Dim selectStatement As Independentsoft.Webdav.Exchange.Sql.Select = New Independentsoft.Webdav.Exchange.Sql.Select(propertyName) Dim from As From = New From(myMailbox.Tasks) Dim where As Where = New Where Dim condition1 As Condition = New Condition(TaskProperty.ContentClass, [Operator].Equals, ContentClassType.Task) Dim condition2 As Condition = New Condition(New Cast(TaskProperty.IsComplete, "boolean"), [Operator].Equals, "true") where.Add(condition1) where.Add(LogicalOperator.AND) where.Add(condition2) Dim query As SqlQuery = New SqlQuery(selectStatement, from, where) Dim multiStatus As MultiStatus = resource.Search(query) 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 Dim taskUrl As String = allRecords(i).Address Console.WriteLine("taskUrl = " & taskUrl) Dim property1() As Independentsoft.Webdav.Exchange.Property = allRecords(i).Property Console.WriteLine("Subject = " & property1(1).Value) Console.WriteLine("Body = " & property1(2).Value) Console.WriteLine("StartDate = " & property1(3).Value) Console.WriteLine("DueDate = " & property1(4).Value) Console.WriteLine("PercentComplete = " & property1(5).Value) Next Console.Read() End Sub End Module