DeleteRecord and MoveRecord Methods Example (VB)
This example demonstrates how to copy, move, edit, and delete the contents of a text file published to a Web folder. Other properties and methods used include GetChildren, ParentURL, Source, and Flush.
Public Sub DeleteRecordX()
'Declare and instantiate object variables
Dim objFileR As Record
Dim objDestFolderR As Record
Dim objDestFileR As Record
Dim objDestFolderRS As Recordset
Dim objStream As Stream
Set objFileR = New Record
Set objDestFolderR = New Record
Set objDestFileR = New Record
Set objDestFolderRS = New Recordset
Set objStream = New Stream
'Open a Record on a text file
objFileR.Open "", "URL=http://websrv/folder/file.txt", _
adModeReadWrite, adOpenIfExists Or adCreateNonCollection
'Edit the contents of the text file
MsgBox "Edit"
objStream.Open objFileR, , adOpenStreamFromRecord
Debug.Print "Source: " + objFileR.Source
Debug.Print "Original text: " + objStream.ReadText
objStream.Position = 0
objStream.WriteText "New Text"
objStream.Position = 0
Debug.Print "New text: " + objStream.ReadText
objStream.Flush
objStream.Close
objFileR.Close
'Reopen Record to see new contents of text file
objFileR.Open "file.txt", "URL=http://websrv/folder/", _
adModeReadWrite, adOpenIfExists Or adCreateNonCollection
objStream.Open objFileR, adModeReadWrite, adOpenStreamFromRecord
Debug.Print "Source: " + objFileR.Source
Debug.Print "Edited text: " + objStream.ReadText
'Copy the file to a subfolder
MsgBox "Copy"
objFileR.CopyRecord , _
"URL=http://websrv/folder/subfolder/file.txt", , , _
adCopyOverWrite
'Delete the original file
MsgBox "Delete"
objFileR.DeleteRecord
'Move the file from the subfolder back to original location
MsgBox "Move Back"
objDestFolderR.Open "", "URL=http://websrv/folder/subfolder/", , _
adOpenIfExists Or adCreateCollection
Set objDestFolderRS = objDestFolderR.GetChildren
objDestFolderRS.MoveFirst
'Position current record at on the correct file
Do While Not _
(objDestFolderRS.EOF Or (objDestFolderRS(0) = "file.txt"))
objDestFolderRS.MoveNext
Loop
'Open a Record on the currect row of the Recordset
objDestFileR.Open objDestFolderRS
'Do the move
objDestFileR.MoveRecord , objDestFolderR.ParentURL + "/file.txt" _
, , , adMoveOverWrite 'objDestFolderR.ParentURL
MsgBox "All done"
End Sub