Share via


ユーザーおよび組織プロファイルを作成する

最終更新日: 2010年3月23日

適用対象: SharePoint Server 2010

以下のコード例は、オブジェクト モデルを使用して、ユーザー プロファイルと組織プロファイルを作成する方法を示しています。このコード例を実行する前に、servername を、実際の値で置換します。

また、Microsoft Visual Studio プロジェクトで以下の参照を追加してください。

  • Microsoft.Office.Server

  • Microsoft.Office.Server.UserProfiles

  • Microsoft.SharePoint

  • System.Web

この例は、ユーザー プロファイルを作成します。

using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
 
namespace CreateUserProfile
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://<servername>"))
            {
                SPServiceContext context = SPServiceContext.GetContext(site);
 
                ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
 
                // choose default user profile subtype as the subtype
                string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User);
                ProfileSubtype subType = psm.GetProfileSubtype(subtypeName);
 
                UserProfileManager upm = new UserProfileManager(context);
 
                // create a user profile and set properties
                UserProfile profile = upm.CreateUserProfile("domain\\alias");
 
                profile.DisplayName = "Display Name";
                profile.ProfileSubtype = subType;
 
                profile.Commit();
            }
        }
    }
}

この例は、組織プロファイルを作成します

using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
 
namespace CreateOrganization
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://<servername>"))
            {
               SPServiceContext context = SPServiceContext.GetContext(site);
 
                ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
 
                // choose default organization profile subtype as the subtype
                string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization);
                ProfileSubtype subType = psm.GetProfileSubtype(subtypeName);
 
                OrganizationProfileManager opm = new OrganizationProfileManager(context);
 
                // choose Root Organization as the parent
                OrganizationProfile parentOrg = opm.RootOrganization;
 
                // create an organization profile and set its display name
                OrganizationProfile profile = opm.CreateOrganizationProfile(subType, parentOrg);
                profile.DisplayName = "Test Org1";
 
                // commit to save changes
                profile.Commit();
            }
        }
    }
}

関連項目

タスク

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