SyncFolderHierarchyType Class

Definition

The SyncFolderHierarchyType class represents a request to synchronize a client folder hierarchy with the computer that is running Microsoft Exchange Server 2007.

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

Examples

The following example shows you how to synchronize a folder hierarchy. Because the SyncState property is set, this folder hierarchy has been synchronized before. This SyncFolderHierarchy operation will return all changes that were made since the synchronization call that is represented by the SyncState property. This call will return all the properties that are defined by the AllProperties folder shape.

static void SyncFolderHierarchy(ExchangeServiceBinding esb)
{ 
    // Create the request.
    SyncFolderHierarchyType <span class="label">request</span> = new SyncFolderHierarchyType();

    // Identify the properties that are synchronized.
    FolderResponseShapeType shape = new FolderResponseShapeType();
    shape.BaseShape = DefaultShapeNamesType.AllProperties;

    // Add synchronized properties to request.
<span class="label">request</span>.FolderShape = shape;

    // Add the synchronization state to the request. This
    // property should be null for the initial synchronization.
<span class="label">request</span>.SyncState = "H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/";

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

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

    foreach (ResponseMessageType rmt in rmta)
    {
        if (rmt.ResponseClass == ResponseClassType.Success)
        {
            SyncFolderHierarchyResponseMessageType sfhrmt = rmt as SyncFolderHierarchyResponseMessageType;

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

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

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

            // This identifies the type of change that occurred on a folder.
            ItemsChoiceType1 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 ItemsChoiceType1.Create:
                        SyncFolderHierarchyCreateOrUpdateType createdFolder = changes[count] as SyncFolderHierarchyCreateOrUpdateType;
                        // TODO: Handle the created folder.
                        if (createdFolder.Item is CalendarFolderType)
                        {
                            // TODO: Cast to calendar folder and handle properties.
                        }
                        else;
                            // TODO: Check and cast to SearchFolderType, TasksFolderType,
                            //       ContactsFolderType, or FolderType.
                        break;

                    case ItemsChoiceType1.Update:
                        SyncFolderHierarchyCreateOrUpdateType updatedFolder = changes[count] as SyncFolderHierarchyCreateOrUpdateType; ;
                        // TODO: Handle the updated folder.    
                        // TODO: Check and cast to one of the five folder types.
                        break;

                    case ItemsChoiceType1.Delete:
                        SyncFolderHierarchyDeleteType deletedFolder = changes[count] as SyncFolderHierarchyDeleteType;
                        // TODO: Get the identifier of the deleted folder.
                        break;
                }
            }
        }
    }
}

The SyncState property returned in the response should be saved for later synchronization requests. Also be aware that the folders that are returned in the response must be cast to the appropriate folder type so that the client application can access all the properties that are available to each folder type.

Important: If updates are returned, the client application must compare the difference between the folders in the response and on the client to determine which changes have occurred.

Because all the change objects do not have the same base type, an object array is returned.

Remarks

To synchronize the items in each folder, use the SyncFolderItemsType proxy object.

Constructors

SyncFolderHierarchyType()

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

Properties

FolderShape

The FolderShape property gets or sets the synchronization folder shape that describes which properties are returned in the 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 optional. This is a read/write property.

SyncState

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

Applies to