다음을 통해 공유


SyncFolderHierarchyType Class

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

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

Syntax

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

Remarks

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

Inheritance Hierarchy

System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.SyncFolderHierarchyType

Example

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 request = new SyncFolderHierarchyType();

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

    // Add synchronized properties to request.
    request.FolderShape = shape;

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

    // Send the request and get the response.
    SyncFolderHierarchyResponseType response = esb.SyncFolderHierarchy(request);

    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 < 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.

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)