Share via


SyncFolderItemsType Class

The SyncFolderItemsType class represents a request to synchronize items in a folder with the computer that is running Microsoft Exchange Server 2007.

Namespace: ExchangeWebServices
Assembly: EWS (in ews.dll)

Syntax

'Declaration
<SerializableAttribute> _
<DesignerCategoryAttribute("code")> _
<XmlTypeAttribute(Namespace:="https://schemas.microsoft.com/exchange/services/2006/messages")> _
<GeneratedCodeAttribute("wsdl", "2.0.50727.42")> _
<DebuggerStepThroughAttribute> _
Public Class SyncFolderItemsType
    Inherits BaseRequestType
[SerializableAttribute] 
[DesignerCategoryAttribute("code")] 
[XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages")] 
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
public class SyncFolderItemsType : BaseRequestType
[SerializableAttribute] 
[DesignerCategoryAttribute(L"code")] 
[XmlTypeAttribute(Namespace=L"https://schemas.microsoft.com/exchange/services/2006/messages")] 
[GeneratedCodeAttribute(L"wsdl", L"2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
public ref class SyncFolderItemsType : public BaseRequestType
/** @attribute SerializableAttribute() */ 
/** @attribute DesignerCategoryAttribute("code") */ 
/** @attribute XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") */ 
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute DebuggerStepThroughAttribute() */ 
public class SyncFolderItemsType extends BaseRequestType
SerializableAttribute 
DesignerCategoryAttribute("code") 
XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") 
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
DebuggerStepThroughAttribute 
public class SyncFolderItemsType extends BaseRequestType

Remarks

To synchronize the folder hierarchy, use the SyncFolderHierarchyType proxy object.

Inheritance Hierarchy

System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.SyncFolderItemsType

Example

The following example shows you how to synchronize the items in the Inbox folder. Because the SyncState property is set, the items in the folder have been synchronized before. This SyncFolderItems operation will return all changes that were made since the synchronization call that is represented by the SyncState property. This call will return a maximum of 100 items, which are represented by their item identifiers and their subject field, if applicable. Also be aware that this call ignores a single item.

static void SyncFolderItems(ExchangeServiceBinding esb)
{ 
    // Create the request.
    SyncFolderItemsType request = new SyncFolderItemsType();

    // Identify the properties that are synchronized.
    ItemResponseShapeType shape = new ItemResponseShapeType();
    shape.BaseShape = DefaultShapeNamesType.IdOnly;
    PathToUnindexedFieldType itemSubject = new PathToUnindexedFieldType();
    itemSubject.FieldURI = UnindexedFieldURIType.itemSubject;
    shape.AdditionalProperties = new BasePathToElementType[1];
    shape.AdditionalProperties[0] = itemSubject;
    
    // Add the synchronized properties to the request.
    request.ItemShape = shape;

    // Define the maximum number of changes returned in the response.
    request.MaxChangesReturned = 100;

    // Identify the folder to synchronize.
    DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
    inbox.Id = DistinguishedFolderIdNameType.inbox;
    request.SyncFolderId = new TargetFolderIdType();
    request.SyncFolderId.Item = inbox;

    // Add the synchronization state to the request.
    request.SyncState = "wQ3YnacHwN3pRYZFQ1jv7HwSZzl/z/wESqUej1h8AAA==";

    // Identify which items should not be synchronized.
    request.Ignore = new ItemIdType[1];
    request.Ignore[0] = new ItemIdType();
    request.Ignore[0].Id = "AAAlAE1BQG1haW5lcmNvbnRvc";
    request.Ignore[0].ChangeKey = "CQAAABYAAAAMoHzy8/QATr21qKEgNudZAG6ns+MG";

    // Send the request and get the response.
    SyncFolderItemsResponseType response = esb.SyncFolderItems(request);

    ArrayOfResponseMessagesType aormt = response.ResponseMessages;
    ResponseMessageType[] rmta = aormt.Items;

    if (rmta[0].ResponseClass == ResponseClassType.Success)
    {
        // Cast the response message to the appropriate type.
        SyncFolderItemsResponseMessageType sfirmt = rmta[0] as SyncFolderItemsResponseMessageType;

        // Get the sync state string to use in later synchronization calls.
        string syncState = sfirmt.SyncState;

        // Get the array of changes that are returned in the response.
        SyncFolderItemsChangesType changeArray = sfirmt.Changes;

        // This contains the array of item changes.
        object[] changes = changeArray.Items;

        // This identifies the type of change that occurred on an item.
        ItemsChoiceType2 changeType;

        for (int count = 0; count < changes.Length; count++)
        { 
            // This identifies the type of change that is represented by the objects
            // in the changes object[].
            changeType = changeArray.ItemsElementName[count];

            // Check for the change type of each folder that is returned in the response.
            switch (changeType)
            {
                case ItemsChoiceType2.Create:
                    SyncFolderItemsCreateOrUpdateType createdItem = changes[count] as SyncFolderItemsCreateOrUpdateType;
                    // TODO: Handle the created item.
                    if (createdItem.Item is TaskType)
                    {
                        // TODO: Cast to task item and handle properties.
                    }
                    else;
                    // TODO: Check and cast for MeetingCancellationMessageType, MeetingResponseMessageType,
                    // MeetingRequestMessageType, MeetingMessageType, DistributionListType, ContactItemType,
                    // CalendarItemType, MessageType, or ItemType types.
                    break;

                case ItemsChoiceType2.Update:
                    SyncFolderItemsCreateOrUpdateType updatedItem = changes[count] as SyncFolderItemsCreateOrUpdateType;
                    // TODO: Handle the updated item.
                    // TODO: Check and cast to one of the 10 item types.
                    break;

                case ItemsChoiceType2.ReadFlagChange:
                    SyncFolderItemsCreateOrUpdateType changeReadFlag = changes[count] as SyncFolderItemsCreateOrUpdateType;
                    // TODO: Check and cast to one of the 10 item types.
                    // TODO: Update the read flag on the local item.
                    break;
                case ItemsChoiceType2.Delete:
                    SyncFolderItemsDeleteType deletedItem = changes[count] as SyncFolderItemsDeleteType;
                    // TODO: Get the identifier of the deleted item.
                    break;
            }
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003,

Target Platforms

Windows 98, Windows 2000, Windows 2000 Server, Windows CE, Windows Longhorn, Windows 98 Second Edition, Pocket PC, Smart Phone, Windows Server 2003, Windows XP Professional with Service Pack 2 (SP2)