Contacts
To access the contacts information stored in Windows Contacts (Start>Programs>Windows Contacts), you can use the following objects:
- System.ContactManager
- System.Contact
The System.ContactManager Object
This object exposes a collection of System.Contact objects through its Contacts collection. The following code gets all the contacts (located in C:\Users\<User_Name>\Contacts) and passes it to the contacts variable:
//---get all contacts---
var contacts = System.ContactManager.Contacts;
To access each contact individually, you can use its item property (zero-based):
//---get a particular contact (first contact)---
var contact = System.ContactManager.Contacts.item(0);
The count property provides the number of contacts retrieved:
//---get a particular contact (first contact)---
var count = System.ContactManager.Contacts.count;
The System.Contact Object
This object contains all the details of a contact. The following code shows how to retrieve all the contacts on the local computer and then prints out the details of each individual contact:
//---get all contacts---
var contacts = System.ContactManager.Contacts;
var result = document.getElementById("result");
result.innerHTML = "";
//---print the details for each contact---
for (i=0; i<contacts.count; i++)
{
result.innerHTML += "<b>" + contacts.item(i).name + "</b><br/>";
result.innerHTML += contacts.item(i).city + "<br/>";
result.innerHTML += contacts.item(i).country + "<br/>";
result.innerHTML += contacts.item(i).defaultEmail + "<br/>";
result.innerHTML += contacts.item(i).filePath + "<br/>";
result.innerHTML += contacts.item(i).homePhone + "<br/>";
result.innerHTML += contacts.item(i).mobilePhone + "<br/>";
result.innerHTML += contacts.item(i).POBox + "<br/>";
result.innerHTML += contacts.item(i).postalCode + "<br/>";
result.innerHTML += contacts.item(i).state + "<br/>";
result.innerHTML += contacts.item(i).street + "<br/>";
result.innerHTML += contacts.item(i).workPhone + "<br/>";
}