Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Use MOVE in WebDAV to Move a Mail Item to Another Folder

View products that this article applies to.


This article demonstrates the use of the Web Distributed Authoring and Versioning (WebDAV) MOVE method to move a mail item from one folder to another.

↑ Back to the top

More information

The following Visual C++ code sample uses the HTTPRequest object to send a MOVE request to the Exchange server. This sample requires Msxml.dll version 2.0 or later.

To run this sample, follow these steps:
  1. Under Public folders, create two new folders and name them "Testfolder1" and "Testfolder2".
  2. In Testfolder1, create a mail item with the subject "test".
  3. In Visual C++, create a new Win 32 console application and name it "Mysample".
  4. Replace the code in the Mysample.cpp file with the following code:
    //TODO: Change the path here if your Msxml.dll file is in a different location.
    #import "c:\winnt\system32\msxml.dll"
    using namespace MSXML;
    //To  use MSXML 6.0 import the dll msxml4.dll instead of msxml.dll as follows 
    // #import "c:\winnt\system32\msxml6.dll"
    // using namespace MSXML2;
    int main(int argc, char* argv[])
       //TODO: Change the line below to reflect your server.
       bstr_t yourServerName = "YourExchangeServername";
       bstr_t sSourceUrl = "http://" + yourServerName + 
       bstr_t sDestUrl = "http://" + yourServerName + 
       bstr_t sMethod = "MOVE";
       //TODO: Change the 2 lines below to reflect your user name and password.
       _variant_t vUser = L"YourDomain\\Administrator";
       _variant_t vPassword = L"password";
       // To use MSXML 6.0 use the following declaration and creation of   pXMLHttpReq
       // IXMLHTTPRequestPtr pXMLHttpReq= NULL;
       // HRESULT hr=pXMLHttpReq.CreateInstance("Msxml2.XMLHTTP.6.0");
       MSXML::IXMLHttpRequest* pXMLHttpReq=NULL;     
       HRESULT hr = ::CoCreateInstance(__uuidof(XMLHTTPRequest), 
       if (S_OK != hr)
          printf("XML Http Request pointer creation failed\n");
          return 0;
       // Call open function.
       _variant_t vAsync = (bool)FALSE;
       pXMLHttpReq->setRequestHeader((bstr_t)"Destination", sDestUrl);
       // Send the request to set the search criteria.
       // OK, get response.   
       long lStatus;
       printf("\n~~~~~~~~\n%d\n", lStatus);
       BSTR bstrResp;
       printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResp);
       _bstr_t bstrAllHeaders;
       bstrAllHeaders = pXMLHttpReq->getAllResponseHeaders();
       printf("\n~~~~~~~~\n%s\n", (char*)bstrAllHeaders);
       BSTR bstrResponseText;
       printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResponseText);      
       catch(_com_error &e)
       printf("Error\a\a\n\tCode = %08lx\n"
          "\tCode meaning = %s\tSource = %s\n\tDescription = %s\n",
          (char*)e.Description() );
       return 0;
  5. Make the changes marked by "TODO:" in the code.
  6. Compile and then run the code.

    Note that the test.eml mail item is no longer in Testfolder1, but is instead in Testfolder2.

↑ Back to the top

Keywords: KB290197, kbmsg, kbhowto, kbarchive, kbnosurvey

↑ Back to the top

Article Info
Article ID : 290197
Revision : 3
Created on : 2/28/2014
Published on : 2/28/2014
Exists online : False
Views : 458