Microsoft KB Archive/290407

= How To Use COPY in WebDAV to Copy a Mail Item to Another Folder =

Article ID: 290407

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q290407



SUMMARY
This article demonstrates the use of the Web Distributed Authoring and Versioning (WebDAV) COPY command to copy a mail item from one folder to another.



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

To run this sample, follow these steps:  Under Public folders, create two new folders and name them &quot;Testfolder1&quot; and &quot;Testfolder2&quot;. In Testfolder1, create a mail item with the subject &quot;test&quot;. In Visual C++, create a new Win32 console application and name it &quot;Mysample&quot;.  Replace the code in the Mysample.cpp file with the following code:
 * 1) include

//TODO: Change the path here if your Msxml.dll file is in a different location.

using namespace MSXML;
 * 1) import &quot;c:\winnt\system32\msxml.dll&quot;

//To use MSXML 4.0 import the dll msxml4.dll instead of msxml.dll as follows // #import &quot;c:\winnt\system32\msxml4.dll&quot; // using namespace MSXML2;

int main(int argc, char* argv[]) {  CoInitialize(NULL); try {        //TODO: Change the line below to reflect your server. bstr_t yourServerName = &quot;YourServerName&quot;;

bstr_t sSourceUrl = &quot;http://&quot; + yourServerName + &quot;/public/Testfolder1/test.eml&quot;; bstr_t sDestUrl = &quot;http://&quot; + yourServerName + &quot;/public/Testfolder2/test.eml&quot;; bstr_t sMethod = &quot;COPY&quot;; //TODO: Change the 2 lines below to reflect your user name and password. _variant_t vUser = L&quot;YourDomainName\\User1&quot;; _variant_t vPassword = L&quot;password&quot;;

// To use MSXML 4.0 use the following declaration and creation of  pXMLHttpReq // IXMLHTTPRequestPtr pXMLHttpReq= NULL; // HRESULT hr=pXMLHttpReq.CreateInstance(&quot;Msxml2.XMLHTTP.4.0&quot;);

MSXML::IXMLHttpRequest* pXMLHttpReq=NULL; HRESULT hr = ::CoCreateInstance(__uuidof(XMLHTTPRequest),      NULL,       CLSCTX_INPROC_SERVER,       __uuidof(IXMLHttpRequest),       LPVOID*)&pXMLHttpReq);

if (S_OK != hr) {     printf(&quot;XML Http Request pointer creation failed\n&quot;); return 0; }

// Call open function. _variant_t vAsync = (bool)FALSE; pXMLHttpReq->open(sMethod,      sSourceUrl,       vAsync,       vUser,       vPassword); pXMLHttpReq->setRequestHeader((bstr_t)&quot;Destination&quot;, sDestUrl); // Send the request to set the search criteria. pXMLHttpReq->send;

// OK, get response. long lStatus; pXMLHttpReq->get_status(&lStatus);

printf(&quot;\n\n%d\n&quot;, lStatus); BSTR bstrResp; pXMLHttpReq->get_statusText(&bstrResp); printf(&quot;\n\n%s\n&quot;, (char*)(bstr_t)bstrResp);

_bstr_t bstrAllHeaders; bstrAllHeaders = pXMLHttpReq->getAllResponseHeaders; printf(&quot;\n\n%s\n&quot;, (char*)bstrAllHeaders);

BSTR bstrResponseText; pXMLHttpReq->get_responseText(&bstrResponseText); printf(&quot;\n\n%s\n&quot;, (char*)(bstr_t)bstrResponseText); }  catch(_com_error &e) {  printf(&quot;Error\a\a\n\tCode = %08lx\n&quot;      &quot;\tCode meaning = %s\tSource = %s\n\tDescription = %s\n&quot;,      e.Error,       e.ErrorMessage,       (char*)e.Source,       (char*)e.Description); }

CoUninitialize; return 0; }                     Make the changes marked by &quot;TODO:&quot; in the code. Compile and then run the code.

Note that the test.eml mail item is now in both Testfolder1 and Testfolder2.</li></ol>

Keywords: kbhowto kbmsg KB290407

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.