Moss user profile (1): Get and traverse
To operate the user profile of Microsoft Office Sharepoint Server 2007, you must first add references to three DLL components:
Microsoft. SharePoint
Microsoft. Office. Server
System. Web
Then you can access it from the userprofilemanager class under the spsite class.
There are two methods to obtain the user profile.
One is to enumerate all user profiles in the field. The other is to obtain a separate user profile.
However, before accessing these user profiles, you need to create a user configuration file in the shared service management in the management center, which is actually "creating or configuring shared services for this server farm" in the management center ", create a website managed by the shared service. Then, when a user visits their "my website" for the first time, their user profile is automatically created.
In the shared service management website, you can view all user configuration files:
① Open the "user configuration file and attributes" first ".
② In my experiment environment, we can see that there are already six user configuration files. Click View user configuration file below to see all user configuration files.
③ User configuration file list
The following describes how to access through the object model. Traverse all user configuration files and find the corresponding user configuration file based on the user name.
Using system; Using system. Collections. Generic; Using system. text; Using Microsoft. SharePoint; Using system. Web; Using Microsoft. Office. server; Using Microsoft. Office. server. administration; Using Microsoft. Office. server. userprofiles; Namespace consoleapplication4 { Class Program { Static void main (string [] ARGs) { Try { Using (spsite site = new spsite ("http: // mossweb: 1111/sites/publish ")) { Servercontext context = servercontext. getcontext (SITE ); Userprofilemanager profilemanager = new userprofilemanager (context ); Console. writeline ("all profiles :"); Foreach (userprofile p in profilemanager) { Console. writeline ("{0 }:{ 1}", p. ID, P. multiloginaccounts [0]); } Console. writeline ("-"); String username = @ "eoffice \ Administrator "; If (profilemanager. userexists (username )) { USERPROFILE profile = profilemanager. getuserprofile (username ); Console. writeline ("found user profile {0}", profile. ID ); Console. writeline ("\ tpersonal site: {0} ({1})", profile. personalsite. rootweb. Title, profile. personalsite. url ); } Else { Console. writeline ("no account found for" + username ); } } } Catch (exception ex) { Console. writeline (ex. Message ); } Console. Readline (); } } } |
Reference: SAMs Microsoft SharePoint 2007 Development unleashed