Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Creating Folders (Exchange Web Services)

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" />
Note Note

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 Exchange Web Services Client Development.

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

Other Resources

CreateFolder Operation
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.