Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Find messages with flag
The following example shows you how to messages with flag.
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 { IsEqualTo restriction1 = new IsEqualTo(MessagePropertyPath.FlagStatus, "1"); //FlagStatus.Complete IsEqualTo restriction2 = new IsEqualTo(MessagePropertyPath.FlagStatus, "2"); //FlagStatus.Marked Or restriction3 = new Or(restriction1, restriction2); FindItemResponse response = service.FindItem(StandardFolder.Inbox, MessagePropertyPath.AllPropertyPaths, restriction3); for (int i = 0; i < response.Items.Count; i++) { if (response.Items[i] is Message) { Message message = (Message)response.Items[i]; Console.WriteLine("Subject = " + message.Subject); Console.WriteLine("FlagStatus = " + message.FlagStatus); Console.WriteLine("FlagIcon = " + message.FlagIcon); Console.WriteLine("FlagCompleteTime = " + message.FlagCompleteTime); Console.WriteLine("FlagRequest = " + message.FlagRequest); 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 restriction1 As New IsEqualTo(MessagePropertyPath.FlagStatus, "1") 'FlagStatus.Complete Dim restriction2 As New IsEqualTo(MessagePropertyPath.FlagStatus, "2") 'FlagStatus.Marked Dim restriction3 As New [Or](restriction1, restriction2) Dim response As FindItemResponse = service.FindItem(StandardFolder.Inbox, MessagePropertyPath.AllPropertyPaths, restriction3) For i As Integer = 0 To response.Items.Count - 1 If TypeOf response.Items(i) Is Message Then Dim message As Message = DirectCast(response.Items(i), Message) Console.WriteLine("Subject = " + message.Subject) Console.WriteLine("FlagStatus = " + message.FlagStatus.ToString()) Console.WriteLine("FlagIcon = " + message.FlagIcon.ToString()) Console.WriteLine("FlagCompleteTime = " + message.FlagCompleteTime) Console.WriteLine("FlagRequest = " + message.FlagRequest) 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
Need help? Ask our developers:
Name*
Email*
Message*