This documentation is archived and is not being maintained.

FindFolderType Class

The FindFolderType class represents a request to find folders in a mailbox.

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

public class FindFolderType : BaseRequestType

The FindFolder operation finds subfolders of an identified folder. The FindFolder operation returns only the first 512 bytes of any streamable property. For Unicode, the FindFolder operation returns the first 255 characters by using a null-terminated Unicode string. Use the GetFolder operation to get additional folder properties.

Restrictions on folder properties, but not item properties, are permitted. Sorting functionality is not available for FindFolder responses. Grouped queries are not available for FindFolder queries.

The following example shows a FindFolder query that returns the following results:

  1. A deep traversal search of the Inbox.

  2. All the properties that are defined for the Default FolderShape in a FindFolder operation.

  3. All folders that have a display name of SentOnlyToMe. The case does not have to match.

  4. A fractional paging scheme that returns at most a single folder that starts after the first folder.

static void FindFolder(ExchangeServiceBinding esb)
    // Create the request and specify the traversal type.
    FindFolderType findFolderRequest = new FindFolderType();
    findFolderRequest.Traversal = FolderQueryTraversalType.Deep;

    // Define the properties to be returned in the response.
    FolderResponseShapeType responseShape = new FolderResponseShapeType();
    responseShape.BaseShape = DefaultShapeNamesType.Default;
    findFolderRequest.FolderShape = responseShape;

    // Identify which folders to search.
    DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
    folderIDArray[0] = new DistinguishedFolderIdType();
    folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;

    // Add the folders to search to the request.
    findFolderRequest.ParentFolderIds = folderIDArray;

    // Restriction based on the folder display name.
    RestrictionType restriction = new RestrictionType();
    PathToUnindexedFieldType fldrRestriction = new PathToUnindexedFieldType();
    fldrRestriction.FieldURI = UnindexedFieldURIType.folderDisplayName;
    // Identify the folder name to restrict on.
    ContainsExpressionType contains = new ContainsExpressionType();
    contains.ContainmentMode = ContainmentModeType.Substring;
    contains.ContainmentModeSpecified = true;
    contains.ContainmentComparison = ContainmentComparisonType.IgnoreCase;
    contains.ContainmentComparisonSpecified = true;
    contains.Item = fldrRestriction;
    contains.Constant = new ConstantValueType();
    contains.Constant.Value = "SentOnlyToMe";
    restriction.Item = contains;
    findFolderRequest.Restriction = restriction;

    // Define the paging scheme for the result set.
    FractionalPageViewType fpvt = new FractionalPageViewType();
    fpvt.MaxEntriesReturned = 1;
    fpvt.MaxEntriesReturnedSpecified = true;
    fpvt.Numerator = 1;
    fpvt.Denominator = 4;
    findFolderRequest.Item = fpvt;

        // Send the request and get the response.
        FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest);

        // Get the response messages.
        ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items;

        foreach (ResponseMessageType rmt in rmta)
            FindFolderResponseMessageType ffrmt = (rmt as FindFolderResponseMessageType);

            FindFolderParentType ffpt = ffrmt.RootFolder;
            BaseFolderType[] folders = ffpt.Folders;
            foreach (BaseFolderType folder in folders)
                // Check folder type
                if (folder is CalendarFolderType)
                    CalendarFolderType fldr = (folder as CalendarFolderType);
                    // TODO: Handle calendar folder
                    // TODO: Handle folders, search folders, tasks folders,
                    // and contacts folder
    catch (Exception e)

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