Gewusst wie: Erstellen von Benutzerprofilen und Organisationsprofilen
Letzte Änderung: Dienstag, 23. März 2010
Gilt für: SharePoint Server 2010
In den folgenden Codebeispielen wird gezeigt, wie Sie mithilfe des Objektmodells Benutzerprofile und Organisationprofile erstellen. Ersetzen Sie vor der Ausführung der Codebeispiele servername durch einen tatsächlichen Wert.
Fügen Sie Ihrem Microsoft Visual Studio-Projekt zudem die folgenden Verweise hinzu:
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
Microsoft.SharePoint
System.Web
Beispiel
In diesem Codebeispiel wird ein Benutzerprofil erstellt.
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();
}
}
}
}
In diesem Codebeispiel wird ein Organisationsprofil erstellt.
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();
}
}
}
}
Siehe auch
Aufgaben
Gewusst wie: Verwenden des Webdienstes zur Änderung von Benutzerprofildaten