Partager via


CreateFolderType Class

The CreateFolderType class represents a request to create a folder.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.BaseRequestType
    ExchangeWebServices.CreateFolderType

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

Syntax

'Declaration
<SerializableAttribute> _
Public Class CreateFolderType _
    Inherits BaseRequestType
'Usage
Dim instance As CreateFolderType
[SerializableAttribute]
public class CreateFolderType : BaseRequestType

Remarks

The CreateFolderType class is used to create tasks folders, search folders, contacts folders, calendar folders, and regular folders. New folders can be extended by using the ExtendedProperty property.

Note

The CreateFolderType class does not add managed folders to a mailbox. For information about how to add managed folders to a mailbox, see CreateManagedFolderRequestType, CreateManagedFolder Operation, and Adding Managed Folders (Exchange Web Services). For a sample that shows you how to implement managed folders, see Managed Folder Selector Sample.

Examples

The following example shows you how to create a set of folders in the Inbox. The example creates a regular folder, a contacts folder, and a tasks folder.

static void CreateFolder(ExchangeServiceBinding esb)
{
    // Identify the folders to create.
    FolderType folder1 = new FolderType();
    ContactsFolderType folder2 = new ContactsFolderType();
    TasksFolderType folder3 = new TasksFolderType();
    folder1.DisplayName = "MyNewRegularFolder";
    folder2.DisplayName = "MyNewContactsFolder";
    folder3.DisplayName = "MyNewTasksFolder";

    // Identify where the new folders are created.
    DistinguishedFolderIdType distFolder = new DistinguishedFolderIdType();
    distFolder.Id = DistinguishedFolderIdNameType.inbox;
    TargetFolderIdType targetID = new TargetFolderIdType();
    targetID.Item = distFolder;

    // Create the request.
    CreateFolderType createFolder = new CreateFolderType();
    createFolder.Folders = new BaseFolderType[] { folder1, folder2, folder3 };
    createFolder.ParentFolderId = targetID;

    try
    {
        // Send the request and get the response.
        CreateFolderResponseType response = esb.CreateFolder(createFolder);

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

        foreach (ResponseMessageType responseMessage in rmta)
        {
            // Perform error checks in production code.
            FolderInfoResponseMessageType firmt = (responseMessage as FolderInfoResponseMessageType);
            BaseFolderType[] folders = firmt.Folders;

            foreach (BaseFolderType folder in folders)
            {
                if (folder is TasksFolderType)
                {
                    TasksFolderType tft = (folder as TasksFolderType);
                    //TODO: Handle the task folder.
                }

                else if (folder is CalendarFolderType)
                {
                    CalendarFolderType cft = (folder as CalendarFolderType);
                    // TODO: Handle the calendar folder.
                }

                else
                {
                    //TODO: Handle the SearchFolderType, ContactsFolderType, and FolderType folders.
                }
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

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.