How to: Use the Web Service to Modify User Profile Data

Microsoft Office SharePoint Server 2007 enables you to update user profile data remotely by using the User Profile Service Web service.

The following example shows you how to update the home phone number of a user. You must add a Web reference to the User Profile Service Web service before you execute this code.

The Web service is located at http://<site URL>/_vti_bin/userprofileservice.asmx.

Before you use this code, replace domainname, username, and telephone numbers (nnnnnnnnnn) with actual values. Also add a Web reference to the following in your Microsoft Visual Studio project:

  • userprofileservice

Example

using System;
using System.Collections.Generic;
using System.Text;

namespace UserProfileWebServiceApp
{
    class Program
    {
        public static localhost.UserProfileService myService =
            new localhost.UserProfileService();
        UserProfileWebService.localhost.PropertyData[] newdata = 
    new UserProfileWebService.localhost.PropertyData[1];
            newdata[0] = 
                new UserProfileWebService.localhost.PropertyData();
            newdata[0].Name = "HomePhone";
            newdata[0].Values = new ValueData[1];
            newdata[0].Values[0] = new ValueData();
            newdata[0].Values[0].Value = "nnnnnnnnnnn";
            newdata[0].IsValueChanged = true;
            myService.ModifyUserPropertyByAccountName("domainname\\username", 
                newdata);

    }
}

See Also

Tasks

How to: Create User Profiles in the User Profile Store