You can give users the ability to update their Windows Live™ Messenger contact list by adding and removing contacts.
By using the Contact List Control, a user can add a contact, remove a contact, and make changes to the group information for a contact. By using the Add Contact Control, a site can enable a user to add a contact and can enable the user to preset which contact to add, the message that the contact will receive, the nickname for the contact, and the group that the contact will be placed in.
If you would like to let users update their contact list by using the Windows Live Messenger Library instead, you will need to incorporate the following functionality into your application:
-
Get the ContactCollection instance for the current user.
-
Subscribe to AddContactCompletedEventHandler.
-
Create a function to add a contact to the contact list (in this example, the function is named addContact()).
-
Create a function to remove a contact from the contact list (in this example, the function is named removeContact()).
-
Add an event handler to run when AddContactCompletedEventHandler is fired (in this example, the event handler is named addContactCompleted()
).
Note: |
|---|
|
When addContact is called, an invitation is sent to the address of a contact whom the user wants to add to the contact list. The recipient has the option to accept or reject the invitation. If the recipient accepts, the contact is added to the user's contact list. If the recipient rejects the invitation, no further action is taken.
|

Procedures
To get the ContactCollection instance for the current user
To subscribe to AddContactCompletedEventHandler
To add a contact to the contact list
To remove a contact from the contact list
-
Locate the contact by using the following address string.
var address = "someone@example.com";
var contact = _contactCollection.find(address, Microsoft.Live.Messenger.IMAddressType.windowsLive);
-
Call removeContact on the ContactCollection instance for the current user.
_contactCollection.remove(contact);

Example
Description
This example shows the basic code for managing contacts. A valid user sign-in session is assumed.
Code
// Get the contact collection for the current user.
_contactCollection = _user.get_contacts();
// Subscribe to addContactCompleted.
_user.add_addContactCompleted(addContactCompleted);
// Add a new contact to the contact list.
function AddNewContact()
{
var address = document.getElementById("txtContact").value;
if (_user)
{
_user.addContact(address, "Invitation message.", null);
}
}
// Call a function to refresh the contact list when a new contact has been added (the displayContacts function is not included in this example).
function addContactCompleted(sender, e)
{
displayContacts();
}

See Also