This documentation is archived and is not being maintained.

Moving Items

EWS Managed API

Topic Last Modified: 2006-06-12

To move items within a public store, use the Record.MoveRecord method. If you move a folder item, all items within the folder are also moved. You cannot use the Record.MoveRecord method to move items from one public store or mailbox store to another.

VBScript

' Variables.
Dim Rec
Dim Conn
Dim NewURL
Dim UrlFrom
Dim UrlTo

UrlFrom = "http://server/public/folder1/test.eml"
UrlTo = "http://server/public/folder2/test.eml"

' Open the connection object.
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ExOLEDB.DataSource"
Conn.Open UrlFrom

' Open the record object.
Set Rec = CreateObject("ADODB.Record")
Rec.Open URLFrom, Conn, adModeReadWrite

' Move the item. Note that if an item
' already exists at the destination URI,
' it will be overwritten by the move.
NewURL = Rec.MoveRecord( , URLTo, , , adMoveOverWrite)

' Clean up.
Rec.Close
Conn.Close


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

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

Conn->Provider = "ExOLEDB.DataSource";

cout << urlfrom << endl;

try {
   // Open the connection.
   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 {

   // Move the item. Note that if an item
   // already exists at the destination URI,
   // it will be overwritten by the move.
   Rec->MoveRecord(
         bstr_t(),
         urlto,
         bstr_t(),
         bstr_t(),
         (MoveRecordOptionsEnum)adMoveOverWrite,
         VARIANT_FALSE);
}
catch(_com_error e) {
   // Handle error or throw.
   throw e;
}

// Clean up.
Rec->Close();
Conn->Close();

Show: