Moss user profile (4): code to create a user configuration file
The creation of the user configuration file has been described earlier. As long as the user has logged on to his or her "my website", it will be created. In fact, through the object model, you can create a user's configuration file in advance, you can save the process that users must log on to my website to create their own configuration files. In addition, it is relatively simple to create a user's configuration file in the object model. You only need to have the permission and provide the account name of the user who needs to create the configuration file.
Like the preceding method, you must first obtain the userprofilemanager object of this important management class from the context.
Spsite site = new spsite ("http: // mossweb: 1111/sites/publish "); Servercontext context = servercontext. getcontext (SITE ); Userprofilemanager profilemanager = new userprofilemanager (context ); |
Then, we can use the following methods:
Method Name |
Description |
Createuserprofile |
Create a user configuration file |
Getchanges |
Obtains the modification history of the user configuration file. |
Getuserprofile |
Get a user configuration file |
Removeuserprofile |
Remove a user configuration file |
Userexists |
Determine whether a user has a configuration file |
Here we use the first method createuserprofile and the last userexists.
The Code is as follows:
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 ); String accountid = @ "eoffice" Administrator "; If (! Profilemanager. userexists (accountid )) { USERPROFILE profile = profilemanager. createuserprofile (accountid ); If (profile = NULL) Console. writeline ("cocould not create profile, an error occurred ."); Else Console. writeline ("user profile created ."); } Else Console. writeline ("user profile for account" + accountid + "already exists ."); } } Catch (exception ex) { Console. writeline (ex. Message ); } Console. Readline (); } } } |
The code in this article comes from reference.
Reference: SAMs Microsoft SharePoint 2007 Development unleashed