Edit

Share via


SyncFolderItemsType Class

Definition

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

public ref class SyncFolderItemsType : ExchangeWebServices::BaseRequestType
public class SyncFolderItemsType : ExchangeWebServices.BaseRequestType
Public Class SyncFolderItemsType
Inherits BaseRequestType
Inheritance
SyncFolderItemsType

Examples

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 <span class="label">request</span> = 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.
<span class="label">request</span>.ItemShape = shape;

    // Define the maximum number of changes returned in the response.
<span class="label">request</span>.MaxChangesReturned = 100;

    // Identify the folder to synchronize.
    DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
    inbox.Id = DistinguishedFolderIdNameType.inbox;
<span class="label">request</span>.SyncFolderId = new TargetFolderIdType();
<span class="label">request</span>.SyncFolderId.Item = inbox;

    // Add the synchronization state to the request.
<span class="label">request</span>.SyncState = "wQ3YnacHwN3pRYZFQ1jv7HwSZzl/z/wESqUej1h8AAA==";

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

    // Send the request and get the response.
    SyncFolderItemsResponseType response = esb.SyncFolderItems(<span class="label">request</span>);

    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 &lt; 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;
            }
        }
    }
}

Remarks

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

Constructors

SyncFolderItemsType()

The SyncFolderItemsType constructor initializes a new instance of the SyncFolderItemsType class.

Properties

Ignore

The Ignore property gets or sets an array of items to skip for synchronization. This property is optional. This is a read/write property.

ItemShape

The ItemShape property gets or sets the shape that describes which properties are returned in the response. This property is required. This is a read/write property.

MaxChangesReturned

The MaxChangesReturned property gets or sets the maximum number of changes that can be returned in a synchronization response. This property is required. This is a read/write property.

SyncFolderId

The SyncFolderId property gets or sets the identity of the folder that contains the items to synchronize. This property is required. This is a read/write property.

SyncScope

The SyncScope property gets or sets one of the SyncFolderItemsScopeType enumeration values that specifies whether just items or items and folder associated information are returned in a synchronization response.

SyncScopeSpecified

The SyncScopeSpecified property gets or sets a Boolean value that specifies whether the SyncScope property is serialized into the SOAP request. This property is required if the SyncScope property is specified.

SyncState

The SyncState property gets or sets the synchronization state identifier. This property is optional with caveats. This is a read/write property.

Applies to