How to copy or move a message from one folder to another folder on a computer that is running Exchange 2000 Server by using Visual C# (310289)



The information in this article applies to:

  • Microsoft Exchange 2000 Server
  • Microsoft XML 3.0
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# 2005

This article was previously published under Q310289

SUMMARY

This article describes how to use Microsoft XML 3.0 to copy or to move a message from one folder to another folder on a computer that is running Microsoft Exchange 2000 Server by using Visual C#.

MORE INFORMATION

To copy or to move a message from one folder to another folder on a computer that is running Exchange 2000, follow these steps:
  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. In the Visual C# Projects types list, click Console Application.

    Note In Visual Studio 2005, click Console Application in the Visual C# list.

    In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default.
  4. Add a reference to Microsoft XML 3.0. To do so, follow these steps:
    1. On the Project menu, click Add Reference.
    2. Click the COM tab, locate Microsoft XML v3.0, and then click Select.

      Note In Visual Studio 2005, you do not have to click Select.
    3. In the Add References dialog box, click OK.
    4. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
  5. In the code window, replace the code with the following:
    using System;
    using System.Reflection;
    
    namespace WebDav
    {
       class Class1
       {   
          public static void Main(String [] args)
          {
             try 
             {
                MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30();
    
                //TODO : Replace with source URL and the destination URL.
                String sSourceURL = "http://ExchServer/Public/MyFolder1/Test.eml";
                String sDestinationURL = "http://ExchServer/Public/MyFolder2/Test.eml";
    
                // COPY
                // TODO: Replace the credentials
                oXMLHttp.open("COPY", sSourceURL, false, @"UserDomain\UserAlias", "UserPassword");
    
                // MOVE
                // TODO: Replace the credentials
                //oXMLHttp.open("MOVE", sSourceURL, false, @"UserDomain\UserAlias", "UserPassword");
    
                oXMLHttp.setRequestHeader("Destination", sDestinationURL);
                oXMLHttp.send(Missing.Value);
    
                Console.WriteLine(oXMLHttp.status);
                Console.WriteLine(oXMLHttp.statusText);
                Console.WriteLine(oXMLHttp.responseText);
             
                oXMLHttp = null;
             }
             catch (Exception e)
             {
                Console.WriteLine("{0} Exception caught.", e);
             }
          }
       }
    }
  6. Search for TODO in the code, and then modify the code for your environment.
  7. Press F5 to build and to run the program.
  8. Make sure that the message has been copied or moved.

Modification Type:MinorLast Reviewed:10/4/2006
Keywords:kbXML kbhowto kbMsg KB310289 kbAudDeveloper