Dela via


Walkthrough: Display a Contact Card (Lync 2010 SDK)

This topic demonstrates how to display the contact information types published by a user represented by Contact. The displayed information can be thought of as a contact card. A Contact exposes two types of property collections.

  • Contact Information: Read only. Contact information types are published by a local user for all other users to access according to established privacy relationships. Because of privacy relationship restrictions, a local user may not be able to access a contact information value published by a remote contact. When this happens, a call into GetContactInformation returns a null value when type requested is not available. For more information about privacy relationships, see Walkthrough: Change the Privacy Relationship of a Contact (Lync 2010 SDK).

  • Contact Settings: Read/Write. The settings choices for a contact are made by the local user and affect interaction with other users individually. For example: The local user John has added Mark to his contact list. John chooses the access level setting of “Workgroup” for the Mark’s contact instance. With this choice, John has given Mark access to his published contact information where appropriate for a member of John’s workgroup. Susan has also added Mark to her contact list but because Susan is in a different workgroup, she chose the access level setting of “Colleague” for Mark’s contact instance. Mark can now see Susan’s published contact information where appropriate for a member of the same enterprise.

This walkthrough demonstrates how your code accesses contact information after subscribing to a contact.

Displaying a Contact Card

  1. Get the LyncClient instance. Verify that the client is signed in to the server. For information about signing in to Microsoft Lync Server 2010, see Walkthrough: Sign In to Lync (Lync 2010 SDK).

  2. Get a Contact instance. For information about searching for a contact or distribution group, see Walkthrough: Search For a Contact (Lync 2010 SDK).

  3. Call the GetContactInformation method on the Contact instance. This call can include use of the ContactInformationType enumeration to obtain specific contact card information and the ContactEndpointType enumeration to determine the type of instances of the ContactEndpoint class found in the collection of contact telephone numbers.

Examples

The following example shows an override of the ToString method on an application class that encapsulates a Contact instance. If a contact was identified to be detailed, this method collects the contact’s name, primary e-mail address, all phone numbers, title, and office using calls to the GetContactInformation method. If a distribution group was identified to be detailed, this method collects the group’s name.

        /// <summary>
        /// Overrides the ToString() method allowing an instance of ContactModel to be added to a UI element that
        /// calls ToString() on this object.
        /// </summary>
        /// <returns>string. A set of contact information items.</returns>
        public override string ToString()
        {
            string returnValue = string.Empty;
            string activityDescription = null;
            List<object> collaborationPhones = null;

            activityDescription = (string)_Contact.GetContactInformation(ContactInformationType.Activity);
            collaborationPhones = (List<object>)_Contact.GetContactInformation(ContactInformationType.ContactEndpoints);

            if (collaborationPhones != null)
            {
                returnValue += "\r\nPhones:";
                foreach (object phone in collaborationPhones)
                {
                    ContactEndpoint anEndpoint = (ContactEndpoint)phone;
                    returnValue += "\r\nType: "
                        + anEndpoint.Type.ToString()
                        + " DisplayName: "
                        + anEndpoint.DisplayName
                        + " Uri: "
                        + anEndpoint.Uri;

                }
            }

            returnValue += activityDescription;
            returnValue += "\r\nPersonal note: " + _Contact.GetContactInformation(ContactInformationType.PersonalNote);
            returnValue += "\r\nOOF note: " + _Contact.GetContactInformation(ContactInformationType.OutOfficeNote);

            return returnValue;
        }

See Also

Concepts

Lync Model API Contacts and Groups Walkthroughs (Lync 2010 SDK)