Independentsoft
Home
Products
Purchase
Support
Downloads
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Find post
The following example shows you how to find post items created in the last month.
C# example
using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver/ews/Exchange.asmx", credential); try { IsGreaterThanOrEqualTo restriction = new IsGreaterThanOrEqualTo(PostPropertyPath.PostedTime, DateTime.Today.AddMonths(-1)); FindItemResponse response = service.FindItem(StandardFolder.Drafts, PostPropertyPath.AllPropertyPaths, restriction); for (int i = 0; i < response.Items.Count; i++) { if (response.Items[i] is Post) { Post post = (Post)response.Items[i]; Console.WriteLine("Subject = " + post.Subject); Console.WriteLine("PostedTime = " + post.PostedTime); Console.WriteLine("Body Preview = " + post.BodyPlainText); Console.WriteLine("----------------------------------------------------------------"); } } Console.Read(); } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Exchange Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim service As New Service("https://myserver/ews/Exchange.asmx", credential) Try Dim restriction As New IsGreaterThanOrEqualTo(PostPropertyPath.PostedTime, DateTime.Today.AddMonths(-1)) Dim response As FindItemResponse = service.FindItem(StandardFolder.Drafts, PostPropertyPath.AllPropertyPaths, restriction) For i As Integer = 0 To response.Items.Count - 1 If TypeOf response.Items(i) Is Post Then Dim post As Post = DirectCast(response.Items(i), Post) Console.WriteLine("Subject = " + post.Subject) Console.WriteLine("PostedTime = " + post.PostedTime) Console.WriteLine("Body Preview = " + post.BodyPlainText) Console.WriteLine("----------------------------------------------------------------") End If Next Console.Read() Catch ex As ServiceRequestException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.XmlMessage) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace