Edit

Share via


FindFolderType Class

Definition

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

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

Examples

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 <span class="label">findFolderRequest</span> = new FindFolderType();
<span class="label">findFolderRequest</span>.Traversal = FolderQueryTraversalType.Deep;

    // Define the properties to be returned in the response.
    FolderResponseShapeType responseShape = new FolderResponseShapeType();
    responseShape.BaseShape = DefaultShapeNamesType.Default;
<span class="label">findFolderRequest</span>.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.
<span class="label">findFolderRequest</span>.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;
<span class="label">findFolderRequest</span>.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;
<span class="label">findFolderRequest</span>.Item = fpvt;

    try
    {
        // Send the request and get the response.
        FindFolderResponseType findFolderResponse = esb.FindFolder(<span class="label">findFolderRequest</span>);

        // 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
                }
                else 
                { 
                    // TODO: Handle folders, search folders, tasks folders,
                    // and contacts folder
                }
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

Remarks

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.

Constructors

FindFolderType()

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

Properties

FolderShape

The FolderShape property gets or sets the shape of the query set. This property is required. This is a read/write property.

Item

The Item property gets or sets the paging type that describes how the query result set is paged in the response. This property gets or sets either an IndexedPageViewType or FractionalPageViewType object. This property is optional. This is a read/write property.

ParentFolderIds

The ParentFolderIds property gets or sets the folders that the FindFolder operation searches. This property is required. This is a read/write property.

Restriction

The Restriction property gets or sets the search parameters that define a folder query. This property is optional. This is a read/write property.

Traversal

The Traversal property gets or sets the traversal scheme that is used to search for folders. This property is required. This is a read/write property.

Applies to