Code snippet for deleting all outlook contacts using VB.Net

 
We can use this code sample for deleting all outlook contact using vb.net language, before using this code sample add reference ‘Microsoft.Office.Interop.Outlook’ library

[VB.Net]

Private Sub DeleteAllContacts()
        Dim oApp As Outlook.Application
        oApp = CreateObject("Outlook.Application")
        Dim oNs As Outlook.NameSpace
        oNs = oApp.GetNamespace("MAPI")
 
        Dim oFolder As Outlook.MAPIFolder
        Dim ContactItem As Outlook.ContactItem
        oFolder = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
 
        For i As Long = 0 To oFolder.Items.Count - 1
            Try
                ContactItem = oFolder.Items.Item(i)
                ContactItem.Delete()
            Catch ex As System.Exception
            End Try
        Next
        MessageBox.Show("All contacts have been deleted successfully")
 
        oFolder = Nothing
        oNs = Nothing
        oApp = Nothing
    End Sub