次の方法で共有


ユーザー プロファイル データを変更する

最終更新日: 2010年1月27日

適用対象: SharePoint Server 2010

ユーザー プロファイル ストアのユーザー プロファイル データの変更は、開発者が最もよく行う作業の 1 つです。コード例は、オブジェクト モデルを使用してユーザー プロファイル データを変更する方法を示しています。

注意

Microsoft SharePoint Server 2010 では、ユーザー プロファイル サービス Web サービスを使用してユーザー プロファイル データを更新することもできます。詳細については、「[方法] Web サービスを使用してユーザー プロファイル データを変更する」を参照してください。

コード例を実行する前に、domainname、username、および nnnnnnnnnn を実際の値に置き換えてください。また、Microsoft Visual Studio プロジェクトで以下への参照を追加してください。

  • Microsoft.Office.Server

  • Microsoft.Office.Server.UserProfiles

  • Microsoft.SharePoint

  • System.Web

この例では、オブジェクト モデルを使用していくつかのユーザー プロファイル プロパティを変更します。

//Updates a user profile
//Creates a user profile. Obtains the property values from the default 
//domain controller or the master connection that is configured on the 
//server
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using System.Web;

namespace UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (SPSite site = new SPSite("https://servername"))
                {
                    SPServiceContext context = SPServiceContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(context);
                    string sAccount = "domainname\\username";
                    UserProfile u = profileManager.GetUserProfile(sAccount);
                    u[PropertyConstants.HomePhone].Value = "nnnnnnnnnn";
                    u[PropertyConstants.CellPhone].Value = "nnnnnnnnnn";
                    u.Commit();



                }
            }
            catch (UserNotFoundException exception)
            {
                Console.WriteLine(exception.ToString());
            }

        }
    }


}

関連項目

タスク

[方法] Web サービスを使用してユーザー プロファイル データを変更する