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 copy or move a message from one folder to another folder on a computer that is running Exchange 2000 Server by using Visual C#


View products that this article applies to.

This article was previously published under Q310289

↑ Back to the top


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#.

↑ Back to the top


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:
a. On the Project menu, click Add Reference.
b. 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.
c. In the Add References dialog box, click OK.
d. 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.

↑ Back to the top


Keywords: KB310289, kbxml, kbmsg, kbhowto

↑ Back to the top

Article Info
Article ID : 310289
Revision : 4
Created on : 12/11/2006
Published on : 12/11/2006
Exists online : False
Views : 474