This documentation is archived and is not being maintained.

ContactManager.DeleteContact Method (PeerName)

Removes the PeerContact associated with the specified PeerName from the ContactManager of the local peer.

Namespace:  System.Net.PeerToPeer.Collaboration
Assembly:  System.Net (in System.Net.dll)

public void DeleteContact(
	PeerName peerName


Type: System.Net.PeerToPeer.PeerName
The PeerName associated with the PeerContact to remove from the ContactManager.


The PeerContact associated with PeerName could not be found in the contact manager.


peerName is null.


This object has had Dispose previously called on it and cannot be used for future operations.


Unable to complete DeleteContact operation.

Calling this method requires a PermissionState of Unrestricted.

The following code example illustrates how to delete a PeerContact from the local ContactManager:

//Enumerating the contacts and letting the user choose which one to delete.
public static void DeleteContact() 
    PeerContactCollection pcc = null;
    string contactToDelete = "";

        pcc = EnumContacts();
        if (pcc == null ||
            pcc.Count == 0)
            Console.WriteLine("Contact list is empty -- no such contact exists.");
        Console.Write("Please enter the nickname of the contact you wish to delete: ");
        contactToDelete = Console.ReadLine();

        foreach (PeerContact pc in pcc)
            if (pc.Nickname.Equals(contactToDelete))
                Console.WriteLine("Contact {0} successfully deleted!", contactToDelete);
        Console.WriteLine("Contact {0} could not be found in the contact collection.", contactToDelete);
    catch (ArgumentNullException argNullEx)
        Console.WriteLine("The supplied contact is null: {0}", argNullEx.Message);
    catch (ArgumentException argEx)
        Console.WriteLine("The supplied contact \"{0}\" could not be found in the Contact Manager: {1}", 
            contactToDelete, argEx.Message);
    catch (PeerToPeerException p2pEx)
        Console.WriteLine("The Peer Collaboration Infrastructure could not delete \"{0}\": {1}",
            contactToDelete, p2pEx.Message);
    catch (Exception ex)
        Console.WriteLine("Unexpected exception when trying to delete a contact : {0}", ex);

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.