Sync Your SharePoint 2010/2007 Contacts with Outlook

In the article you will see how easy it is to leverage the Social Web Services in SharePoint in your Outlook Add-Ins. In particular I show you how to call the User Profile Services to pull your colleagues from SharePoint and create Outlook contacts.
In 3 Solutions for Accessing SharePoint 2010 Data in Office 2010 you will walkthrough the details on how everything works. Here is a visual walkthrough of the solution.

From SharePoint

Sync Your SharePoint 2010/2007 Contacts with Outlook

To Outlook

Sync Your SharePoint 2010/2007 Contacts with Outlook

Contact Details

Sync Your SharePoint 2010/2007 Contacts with Outlook

Build a Custom Outlook Ribbon

Sync Your SharePoint 2010/2007 Contacts with Outlook

The Code

private void button1_Click(object sender, RibbonControlEventArgs e) 

{

//Instantiate the Web service.

UserProfileService userProfileService =

new UserProfileService();



//Use the current user log-on credentials.

userProfileService.Credentials =

System.Net.CredentialCache.DefaultCredentials;



//Get My Colleagues

ContactData[] contacts =

userProfileService.GetUserColleagues(

"contoso\\danj");



//Add each Colleague as an Outlook Contact

foreach (ContactData contact in contacts)

{

//Get the users detailed Properties

PropertyData[] properties =

userProfileService.GetUserProfileByName(contact.AccountName);



//Create a new Outlook Contact

Outlook.ContactItem newContact =

Globals.ThisAddIn.Application.

CreateItem(Outlook.OlItemType.olContactItem);



//Set the Contact Properties

newContact.FullName = contact.Name;

newContact.FirstName = properties[2].Values[0].Value.ToString();

newContact.LastName = properties[4].Values[0].Value.ToString();

newContact.Email1Address = properties[41].Values[0].Value.ToString();

newContact.Department = properties[9].Values[0].Value.ToString();

newContact.JobTitle = properties[10].Values[0].Value.ToString();

newContact.CustomerID = properties[0].Values[0].Value.ToString();

newContact.PrimaryTelephoneNumber = properties[8].Values[0].Value.ToString();

//Notes field

newContact.Body = properties[13].Values[0].Value.ToString();



//Download the users profile image from SharePoint

SetContactImage(properties, newContact);



newContact.Save();

}

}







You can learn more about SharePoint’s Social Data features here on MSDN. This provides guidance for programmability issues related to user profiles and social data in Microsoft SharePoint Server 2010. In addition, this includes topics that offer step-by-step, how-to procedures for programming with user profiles and audiences.



Note: This article come from MSDN Blog