共用方式為


Sync Your SharePoint Contacts with Outlook

In this article, Donovan and I talk about a number of techniques to access SharePoint data from your Office applications. Donovan has information on his blog on how to get a development environment up and running to try out these examples.

  • Using the client object model to access a SharePoint External list.

  • Using WCF Data Services to access SharePoint standard lists.

  • Using SharePoint web services to access SharePoint Social Services.

     

    Office Add-Ins: 3 Solutions for Accessing SharePoint Data in Office 2010 SharePoint 2010 introduces a number of new ways to access business data and present it to the user. We’ll show you several options that range from no-code solutions to fully integrated Office add-ins.

    Donovan Follette and Paul Stubbs

    Sync SharePoint Social Data 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 the article you will walkthrough the details on how everything works. Here is a visual walkthrough of the solution.

    From SharePoint

    image

    To Outlook

    image

    Contact Details

    image

    Build a Custom Outlook Ribbon

    image

    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. 

    Also be sure to visit Donovan’s blog as a great resource for Office development.