Code snippet for deleting all outlook contacts using VB.Net

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


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
                ContactItem = oFolder.Items.Item(i)
            Catch ex As System.Exception
            End Try
        MessageBox.Show("All contacts have been deleted successfully")
        oFolder = Nothing
        oNs = Nothing
        oApp = Nothing
    End Sub