Share via


Copying Items

Copying Items

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

To copy an item from one location to another within the same store, use the Record.CopyRecord method. If you copy a folder, all items and subfolders are also copied. You cannot use the Record.CopyRecord method to copy items from one public store or mailbox store to another.

VBScript

Dim Rec
Dim Info
Dim InfoNT
Dim sUrlRoot
Dim sUrl
Dim sUrlDest
Set Info   = CreateObject("ADSystemInfo")
Set InfoNT = CreateObject("WinNTSystemInfo")

SUrlRoot = "http://" & InfoNT.Computername & "." & Info.DomainDNSName & "/public/"
sUrl     = sUrlRoot & "test_folder/test1.txt"
SurlDest = sUrlRoot & "test_folder2/test1.txt"

copyItem sUrl, sUrlDest, Nothing


Sub copyItem( sUrl, sUrlDest, Conn )

  Dim Rec

 ' Did caller pass a Connection object reference?
 If Not ( VarType(Conn) = vbObject AND TypeName(Conn) = "Connection" ) Then
   Set Conn = CreateObject("ADODB.Connection")
   Conn.Provider = "ExOLEDB.DataSource"
   Conn.Open sUrl
 End If

 Set Rec = CreateObject("ADODB.Record")

 Rec.Open sURL, Conn, adModeReadWrite

 ' Note that if an item already exists at the destination URI,
 ' it will be overwritten by the copy.
 Rec.CopyRecord ,sUrlDest, , , adCopyOverWrite

 ' Close record and connection.
 Rec.Close
 Conn.Close

End Sub

C++

#import <msado15.dll> no_namespace
#import <cdoex.dll> no_namespace

// Variables.
_RecordPtr Rec(__uuidof(Record));
_ConnectionPtr Conn(__uuidof(Connection));
bstr_t urlfrom = "https://server/public/folder/test.eml";
bstr_t urlto = "http:/server/public/folder2/test.eml";

Conn->Provider = "ExOLEDB.DataSource";

// Open connection.
try {
   Conn->Open(urlfrom, bstr_t(""), bstr_t(""),-1);
}
catch(_com_error e) {
   // Handle error or throw.
   throw e;
}

try {
   // Open the record.
   Rec->Open(
            variant_t(urlfrom),
            variant_t((IDispatch*)Conn, true),
            adModeReadWrite,
            adFailIfNotExists,
            adOpenSource,
            bstr_t(""),
            bstr_t(""));
}
catch(_com_error e) {
   // Handle error or throw.
   throw e;
}

try {

   // Copy the record.
   // Note that if an item already exists at the
   // destination URI, it will be overwritten by the copy.
   Rec->CopyRecord(
         bstr_t(),
         urlto,
         bstr_t(),
         bstr_t(),
         (CopyRecordOptionsEnum)adCopyOverWrite,
         VARIANT_FALSE);
}
catch(_com_error e) {
   // Handle error or throw.
   throw e;
}

// Close connection and record.
Conn->Close();
Rec->Close();

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.