Accessing Contacts

Applies to: SharePoint Workspace 2010 | Visual Studio 2008

You can get contacts associated with an account, and you can access not only contact information such as phone numbers or email addresses, but also status of the contact in the workspace, such as whether they are online or how long they have been idle in the workspace. You can also get information about contacts in the Public Directory. For more information, see GrooveContacts Web Service.

Reading Contacts

You can use the Read method to get information about contacts in your personal list, which is associated with your account.

To access to contacts in the Public Directory or in a Microsoft® Office Groove® Management Server, you can call Search to search for contacts based on a text comparison and Fetch to make the contacts accessible.

The following example shows you how to get the personal contacts for a given account.

// Get the Account from GrooveAccounts.Read2
GrooveAccounts.Account2 account2 = ... ;

// Create new service and header
GrooveContacts.GrooveContacts contactsSvc = new GrooveContacts.GrooveContacts();
contactsSvc.GrooveRequestHeaderValue = new GrooveContacts.GrooveRequestHeader();

// Get IdentityURL from first Identity2 in Account2
contactsSvc.GrooveRequestHeaderValue.GrooveIdentityURL = 
  account2.Identities[0].URI;

// Get the request key, HTTP address, and port number.
// See examples in Reading Groove Registry Keys
string requestKey = ... ;
string HTTPAddressAndPort = ... ;

contactsSvc.GrooveRequestHeaderValue.GrooveRequestKey = requestKey ;

// Get the Post URL from Account2
contactsSvc.Url = HTTPAddressAndPort + account2.Contacts;

// Read personal contacts
GrooveContacts.Contact [] contacts = 
  contactsSvc.Read("urn:groove.net:Core.PersonalContact");

Retrieving a VCard

A common operation that you might need to perform is retrieving a VCard from a contact. The following example shows how to get the VCard of a user who has sent a Groove message. Once you have the VCard, you can get the user's email address. See Accessing Groove Messages for an example of how to get messages.

string vCardURI = "";
string primaryEmailAddr = "";

// incomingMessage is a message returned by GrooveMessages.Read
string identityURL = incomingMessage.MessageHeader.Sender.URI;

...
// Read personal contacts
GrooveContacts.Contact [] contacts = 
  contactsSvc.Read("urn:groove.net:Core.PersonalContact");

// cycle through contacts, finding the one that matches the identity URL
for (int i = 0; i < contacts.Length; i++)
{
  GrooveContacts.Contact contact = contacts[i];
  if (contact.URI == identityURL)
  {
    vCardURI = contact.VCard;
    break;
  }
}

// If the IdentityURL matches, this is the contact being searched for. 
// Create a VCard service and get the information. Note that the
// sender may not be in the contact list. 
if (vCardURI.Length > 0)
{
  // Get the Account from GrooveAccounts.Read2
  GrooveAccounts.Account2 account2 = ... ;

  // Create a new GrooveVCard service and header
  GrooveVCard.GrooveVCard vCardSvc = new GrooveVCard.GrooveVCard();
  vCardSvc.GrooveRequestHeaderValue = new GrooveVCard.GrooveRequestHeader();

  // Get IdentityURL from first Identity2 in Account2
  vCardSvc.GrooveRequestHeaderValue.GrooveIdentityURL = 
  account2.Identities[0].URI;

  // Get the request key, HTTP address, and port number.
  // See examples in Reading Groove Registry Keys
  string requestKey = ... ;
  string HTTPAddressAndPort = ... ;

  vCardSvc.GrooveRequestHeaderValue.GrooveRequestKey = requestKey;
  vCardSvc.Url = HTTPAddressAndPort + vCardURI;
    
  // Use the service to read the contact information
  GrooveVCard.vCard vCard = vCardSvc.Read();

  // Take the first available email address from the VCard
  if (vCard.EmailAddresses.Length > 0)
    primaryEmailAddr = vCard.EmailAddresses[0].EmailAddress;
}

See Also

Reference

GrooveContacts Web Service

Concepts

Accessing the Groove Web Services Hierarchy

Accessing Groove Messages