Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Creating Folders
Collapse the table of content
Expand the table of content

Creating Folders by using EWS in Exchange 2010

Last modified: May 21, 2009

Applies to: Exchange Server 2007 | Exchange Server 2010

You can use Exchange Web Services to create folders to organize items and other folders.

The following example shows you how to create two folders in the Inbox. One of the folders that is created in this example is a Tasks folder.

static void CreateFolder(ExchangeServiceBinding esb)
    // Create the request.
    FolderType folder = new FolderType();
    FolderType folder2 = new FolderType();
    folder.DisplayName = "TestFolder";
    folder2.DisplayName = "TestFolder2";
    folder2.FolderClass = "IPF.Task";

    DistinguishedFolderIdType distFolder = new DistinguishedFolderIdType();
    distFolder.Id = DistinguishedFolderIdNameType.inbox;
    TargetFolderIdType targetID = new TargetFolderIdType();
    targetID.Item = distFolder;

    CreateFolderType createFolder = new CreateFolderType();
    createFolder.Folders = new FolderType[] { folder, folder2 };
    createFolder.ParentFolderId = targetID;

        // Send the request and get the response.
        CreateFolderResponseType response = esb.CreateFolder(createFolder);
        // Get the response messages.
        ResponseMessageType[] rmta = response.ResponseMessages.Items;

        foreach (ResponseMessageType rmt in rmta)
            // Cast to the correct response message type.
            if (((FolderInfoResponseMessageType)rmt).ResponseClass == ResponseClassType.Success)
                Console.WriteLine("Folder added to mailbox.");

    catch (Exception e)

The following XML example shows the request message that is sent from the client to the server.

<?xml version="1.0" encoding="utf-8"?>
<CreateFolder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <ParentFolderId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <DistinguishedFolderId Id="inbox" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
  <Folders xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <Folder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
    <Folder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">

The following XML example shows the XML response message that is sent from the server to the client.

<CreateFolderResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <ResponseMessages xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <CreateFolderResponseMessage ResponseClass="Success">
        <Folder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
          <FolderId Id="AQApAH" ChangeKey="AQAAABY" />
    <CreateFolderResponseMessage ResponseClass="Success">
        <TasksFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
          <FolderId Id="AQApAH" ChangeKey="BAAAABY" />

The folder identifier and change key have been shortened to preserve readability.

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by MicrosoftVisual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.

You can also create a folder by using an XML message. For more information, see CreateFolder Operation.

For information about compiling the code, see EWS Client Development in Exchange 2010.

The namespace that is created when the proxy is generated must also be added to this example.

© 2015 Microsoft