Export (0) Print
Expand All

Deleting Folders

Exchange Server 2010

You can use Exchange Web Services to delete folders by using a unique identifier.

The following example shows how to delete a folder.

static void DeleteFolder(ExchangeServiceBinding esb)
    // Create the request.
    DeleteFolderType deleteFolderRequest = new DeleteFolderType();
    deleteFolderRequest.DeleteType = DisposalType.HardDelete;

    FolderIdType[] folderIDArray = new FolderIdType[1];
    folderIDArray[0] = new FolderIdType();
    folderIDArray[0].Id = "AQApAH";
    deleteFolderRequest.FolderIds = folderIDArray;

        // Send the request and get the response.
        DeleteFolderResponseType deleteResponse = esb.DeleteFolder(deleteFolderRequest);

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

        foreach (ResponseMessageType rmt in rmta)
            // Cast to the correct response message type.
            if (rmt.ResponseClass == ResponseClassType.Success)
                Console.WriteLine("Folder deleted from mailbox.");
    catch (Exception e)
        Console.WriteLine("Exception: " + e.Message);

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

<DeleteFolder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <FolderIds xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <FolderId Id="AQApAH"  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.

<DeleteFolderResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <ResponseMessages xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <DeleteFolderResponseMessage ResponseClass="Success">

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.

Note Note

The folder ID has been shortened to preserve readability. Folder identifiers are returned in the FindFolder, CopyFolder, CreateFolder, CreateManagedFolder, GetFolder, MoveFolder, and UpdateFolder responses.

For information about compiling the code, see Exchange Web Services Client Development.

© 2014 Microsoft