Deleting Objects (ADO)
Topic Last Modified: 2006-06-12
Example
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.
' Deleting Objects Using ADO
' This sample shows how to delete an object by specifying its local path.
' Make reference to the ADO 2.5 library.
' Make reference to the Active DS Type Library.
Private Sub deleteitem()
Dim strDomainName As String
Dim strLocalPathOfObject As String
Dim strUser As String
strDomainName = GetDomainDNSName()
strUser = "user1"
' Sample 1: Delete a folder from "MBX".
' Specify the path of the folder to be deleted.
strLocalPathOfObject = "MBX/" & strUser & "/Outbox/TestFolder"
Call TestDeleteObjects(strDomainName, strLocalPathOfObject)
' Sample 2: Delete a folder from "Public Folders".
strLocalPathOfObject = "Public Folders/TestFolder"
Call TestDeleteObjects(strDomainName, strLocalPathOfObject)
' Sample 3: Delete a file from "MBX".
strLocalPathOfObject = "MBX/" & strUser & "/Deleted Items/Hello.txt"
Call TestDeleteObjects(strDomainName, strLocalPathOfObject)
End Sub
Private Function GetDomainDNSName() As String
Dim Info As New ADSystemInfo
Dim strDomain As String
strDomain = Info.DomainDNSName
GetDomainDNSName = strDomain
End Function
Private Sub TestDeleteObjects(strDomainName As String, strLocalPathOfObject As String)
Dim Rec As New ADODB.Record
Dim strObjectUrl As String
' Specify the URL to the item to be deleted.
strObjectUrl = "file://./backofficestorage/" & _
strDomainName & "/" & strLocalPathOfObject
MsgBox "strObjectUrl : " & strObjectUrl
' Open the record.
Rec.Open strObjectUrl, , adModeReadWrite
' Delete the object.
Rec.DeleteRecord
' Close the record.
Rec.Close
' Clean up.
Set Rec = Nothing
If Err.Number = 0 Then
Debug.Print "Good Job!"
End If
End Sub