Export (0) Print
Expand All

GetFolderType class

The GetFolderType class represents a request to get folders from a mailbox.

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

'Declaration
<SerializableAttribute> _
Public Class GetFolderType _
	Inherits BaseRequestType
'Usage
Dim instance As GetFolderType

The GetFolder operation is used to get regular, managed, and default folders from an Exchange mailbox.

The following example shows you how to get two folders. One of the folders is identified by the FolderId property and the other folder is identified by the DistinguishedFolderId property. The response will contain the properties that are defined for the AllProperties response shape and the additional information that is provided by the ManagedFolderInformation property if it applies to the folder.

static void GetFolder(ExchangeServiceBinding esb)
{ 
    // Identify the folders to get.
    FolderIdType folder1 = new FolderIdType();
    DistinguishedFolderIdType sentitems = new DistinguishedFolderIdType();
    folder1.Id = "AQAlAE1BQG";
    sentitems.Id = DistinguishedFolderIdNameType.sentitems;

    // Identify the folder properties to return.
    FolderResponseShapeType properties = new FolderResponseShapeType();
    PathToUnindexedFieldType ptuft = new PathToUnindexedFieldType();
    ptuft.FieldURI = UnindexedFieldURIType.folderManagedFolderInformation;
    PathToUnindexedFieldType[] ptufts = new PathToUnindexedFieldType[1] { ptuft };
    properties.AdditionalProperties = ptufts; 
    properties.BaseShape = DefaultShapeNamesType.AllProperties;

    // Form the get folder request.
    GetFolderType request = new GetFolderType();
    request.FolderIds = new BaseFolderIdType[2] { folder1, sentitems };
    request.FolderShape = properties;

    try
    {
        // Send the request and get the response.
        GetFolderResponseType response = esb.GetFolder(request);
        ArrayOfResponseMessagesType aormt = response.ResponseMessages;
        ResponseMessageType[] rmta = aormt.Items;

        foreach (ResponseMessageType rmt in rmta)
        {
            if (rmt.ResponseClass == ResponseClassType.Success)
            {
                FolderInfoResponseMessageType firmt;
                firmt = (rmt as FolderInfoResponseMessageType);
                BaseFolderType[] folders = firmt.Folders;

                foreach (BaseFolderType folder in folders)
                {
                    if (folder is CalendarFolderType)
                    {
                        CalendarFolderType calendar;
                        calendar = (folder as CalendarFolderType);
                    }
                    else if (folder is ContactsFolderType)
                    {
                        // Handle the contacts folder.
                    }
                    else
                    { 
                        // Handle SearchFolderType, TasksFolderType,
                        // and FolderType.
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

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