Howto: WebDAV MOVE using VBScript


‘ This example shows how to do a MOVE of a message to a folder.  
 
‘NOTE:
‘  • Copying or Moving items across stores is not supported (that includes maiboxes)
‘  • You will get a 404 (Resource Not Found) if the source item does not exist.
‘  • A status  of 204 (No Content) will be returned if the destination item already exists
‘  • To force an overwrite of an existing item, add a header of “Overwrite” set to “T”.
‘  • Be careful specifying the destination – Example: Using a message as the source and
‘    a folder as a destination may mess-up the folder.


‘———————————————————————————
‘ DoCopyMove – Used to move an item from one folder to another in the same store.
‘  sSourceURL       – item being moved/copied
‘  sDestinationURL  – the URL it is going to
‘  bCopy            – TRUE if copying or FALSE if moving
‘  sUser            – User ID for logging in.  Set to “” if using windows authentication
‘  sPassword        – Password for logging in.  Set to “” if using windows authentication
‘ NOTE:
‘   Copying or Moving items across stores is not supported
‘   You will get a 404 (Resource Not Found) if the source item does not exist.
‘   A status204 (No Content) will be returned if the destination item already exists
‘——————————————————————————–
Function DoCopyMove(sSourceURL, sDestinationURL, bCopy, sUser, sPassword )
    Set oXMLHttp = CreateObject(“microsoft.xmlhttp”) ‘ = New MSXML2.XMLHTTP30
    Dim sVerb 
   
    If bCopy = True Then
        sVerb = “COPY”
    Else
        sVerb = “MOVE”
    End If
   
    If sUser <> “” Then
        oXMLHttp.Open sVerb, sSourceURL, False, sUser, sPassword   
    Else
        oXMLHttp.Open sVerb, sSourceURL, False ‘, sUser, sPassword   
    End If
 
    oXMLHttp.setRequestHeader “Destination”, sDestinationURL


    ‘ Send the stream across
    oXMLHttp.Send
   
    If (oXMLHttp.Status >= 200 And oXMLHttp.Status < 300) Then
          wscript.echo “Success!   ” & “Results = ” & oXMLHttp.Status & “: ” & oXMLHttp.statusText
        ElseIf oXMLHttp.Status = 401 Then
          wscript.echo “You don’t have permission to do the job! Please check your permissions on this item.”
        Else
          wscript.echo “Request Failed.  Results = ” & oXMLHttp.Status & “: ” & oXMLHttp.statusText
    End If


    DoCopyMove = oXMLHttp.statusText


    Set oXMLHttp = Nothing
End Function


Dim sSourceURL
Dim sDestinationURL
Dim sUserName
Dim sPassword
Dim sRet


sUserName = “Administrator”     ‘ TODO: change
sPassword  = “test”    ‘ TODO: change
sSourceURL= “http://myexserver/exchange/Administrator/Inbox/testabcd.EML” ‘ TODO: change
sDestinationURL = “http://myexserver/exchange/Administrator/Inbox/test/testabcd.EML” ‘ TODO: change
 
sRet = DoCopyMove(sSourceURL, sDestinationURL, False, sUserName, sPassword)


wscript.echo sRet

Comments (0)

Skip to main content