SyncFolderHierarchyType 类

定义

SyncFolderHierarchyType表示将客户端文件夹层次结构与运行 Microsoft Exchange Server 2007 的计算机同步的请求。

public ref class SyncFolderHierarchyType : ExchangeWebServices::BaseRequestType
public class SyncFolderHierarchyType : ExchangeWebServices.BaseRequestType
Public Class SyncFolderHierarchyType
Inherits BaseRequestType
继承
SyncFolderHierarchyType

示例

以下示例演示如何同步文件夹层次结构。 SyncState由于设置了 属性,因此以前已同步此文件夹层次结构。 此 SyncFolderHierarchy作将返回自 属性表示 SyncState 的同步调用以来所做的所有更改。 此调用将返回由 AllProperties 文件夹形状定义的所有属性。

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

SyncState响应中返回的属性应保存,以供以后的同步请求使用。 另请注意,响应中返回的文件夹必须强制转换为适当的文件夹类型,以便客户端应用程序可以访问每个文件夹类型可用的所有属性。

重要提示:如果返回更新,客户端应用程序必须比较响应中文件夹与客户端上的文件夹之间的差异,以确定发生了哪些更改。

由于所有更改对象都不具有相同的基类型,因此将返回对象数组。

注解

若要同步每个文件夹中的项目,请使用 SyncFolderItemsType 代理对象。

构造函数

SyncFolderHierarchyType()

构造 SyncFolderHierarchyType 函数初始化 类的新实例 SyncFolderHierarchyType

属性

FolderShape

属性 FolderShape 获取或设置描述响应中返回的属性的同步文件夹形状。 此属性是必需项。 这是一个读/写属性。

SyncFolderId

属性 SyncFolderId 获取或设置包含要同步的项的文件夹的标识。 此属性可选。 这是一个读/写属性。

SyncState

属性 SyncState 获取或设置同步状态标识符。 此属性是可选的,需要注意。 这是一个读/写属性。

适用于