Share via


Moving/Copying Using ADO

Moving/Copying Using ADO

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.

Visual Basic

Note  The following example uses a file URL with the Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme. Using The HTTP: URL Scheme allows both client and server applications to use a single URL scheme.

' CDO: Moving/Copying Using CDOEX
' This sample shows how to move/copy objects.
' Add a reference to Microsoft ActiveX Data Objects 2.5 Library.
' Add a reference to Active DS Type Library.


Private Sub Command1_Click()
    Dim strPathOfSourceObject As String
    Dim strPathOfDestFolder As String
    Dim strDomainName As String
    Dim strUser As String

    ' Specify the domain and the user.
    strDomainName = GetDomainDNSName()
    strUser = "user1"


    ' Sample 1: Copy folders in MBX.
    strPathOfSourceObject = "MBX/" & strUser & "/Outbox/HelloFolder"
    strPathOfDestFolder = "MBX/" & strUser & "/Deleted Items"
    Call CopyMoveObjects(strDomainName, strPathOfSourceObject, strPathOfDestFolder, 0)


    ' Sample 2: Move folders in Public Folders.
    strPathOfSourceObject = "Public Folders/SourceFolder"
    strPathOfDestFolder = "Public Folders/DestFolder"
    'Call CopyMoveObjects(strDomainName, strPathOfSourceObject, strPathOfDestFolder, 1)


    ' Sample 3: Move a file in MBX.
    strPathOfSourceObject = "MBX/" & strUser & "/Outbox/TestFolder/Hello.txt"
    strPathOfDestFolder = "MBX/" & strUser & "/Deleted Items"
    'Call CopyMoveObjects(strDomainName, strPathOfSourceObject, strPathOfDestFolder, 0)

    Unload Me
End Sub



' bOption:
' False: copy
' True - Move
'
Private Sub CopyMoveObjects(strDomainName As String, _
                                strLocalPathOfSourceObject As String, _
                                strLocalPathOfDestFolder As String, _
                                bOption As Boolean)
    Dim Rec As New ADODB.Record
    Dim strSourceObjectUrl As String
    Dim strDestFolderURL As String
    Dim strNewFolderName As String

    ' Set the strURL to the location of the folders.
    strSourceObjectUrl = "file://./backofficestorage/" & _
                 strDomainName & "/" & strLocalPathOfSourceObject

    ' Open the record.
    ' The adModeReadWrite enum is required.
    Rec.Open strSourceObjectUrl, , adModeReadWrite
    strNewFolderName = Rec.Fields("DAV:displayname")

    strDestFolderURL = "file://./backofficestorage/" & _
                 strDomainName & "/" & strLocalPathOfDestFolder

    If bOption = False Then

       ' Copy the folder from the source location to the destination folder.
       ' Note that if an item already exists at the destination URI,
       ' it will be overwritten by the copy.
       Rec.CopyRecord strSourceObjectUrl, strDestFolderURL & "/" & _
          strNewFolderName, , , adCopyOverWrite

    ' The adModeReadWrite enum is required.
    Else
       ' Move the folder from the source location to the destination folder.
       ' Please note that if an item already exists at the destination URI,
       ' it will be overwritten by the copy.
       Rec.MoveRecord strSourceObjectUrl, strDestFolderURL & "/" & _
          strNewFolderName, , , adMoveOverWrite
    End If


    ' Close the record.
    Rec.Close

    ' Clean up.
    Set Rec = Nothing

    If Err.Number = 0 Then
      Debug.Print "Good Job!"
    End If

End Sub


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.