Microsoft Knowledge Base Email Alertz

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.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 290407 - Last Review: October 19, 2009 - Revision: 3.0

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

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:
  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 Win32 console application and name it "Mysample".
  4. Replace the code in the Mysample.cpp file with the following code:
    #include<stdio.h>
    
    //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 msxml6.dll instead of msxml.dll as follows 
    // #import "c:\winnt\system32\msxml6.dll"
    // using namespace MSXML2;
    
    int main(int argc, char* argv[])
    {
       CoInitialize(NULL);
       try
       {
             //TODO: Change the line below to reflect your server.
       bstr_t yourServerName = "YourServerName";
    
       bstr_t sSourceUrl = "http:/" + yourServerName +
          "/public/Testfolder1/test.eml";
       bstr_t sDestUrl = "http:/" + yourServerName +
          "/public/Testfolder2/test.eml";
       bstr_t sMethod = "COPY";
             
       //TODO: Change the 2 lines below to reflect your user name and password.
       _variant_t vUser = L"YourDomainName\\User1";
       _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), 
          NULL, 
          CLSCTX_INPROC_SERVER, 
          __uuidof(IXMLHttpRequest), 
          LPVOID*)&pXMLHttpReq);
        
    
       if (S_OK != hr)
       {
          printf("XML Http Request pointer creation failed\n");
          return 0;
       }
    
       // Call open function.
       _variant_t vAsync = (bool)FALSE;
       pXMLHttpReq->open(sMethod, 
          sSourceUrl, 
          vAsync, 
          vUser, 
          vPassword);
       pXMLHttpReq->setRequestHeader((bstr_t)"Destination", sDestUrl);
     
       // Send the request to set the search criteria.
       pXMLHttpReq->send();
    
       // OK, get response.   
       long lStatus;
       pXMLHttpReq->get_status(&lStatus);
    
       printf("\n~~~~~~~~\n%d\n", lStatus);
       BSTR bstrResp;
       pXMLHttpReq->get_statusText(&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;
       pXMLHttpReq->get_responseText(&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",
          e.Error(), 
          e.ErrorMessage(), 
          (char*)e.Source(), 
          (char*)e.Description());
       }
    
       CoUninitialize(); 
       
       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 now in both Testfolder1 and Testfolder2.

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 Parser 3.0
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft XML Core Services 6.0
Keywords: 
kbhowto kbmsg KB290407
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate