Moss user profile (4): code to create a user configuration file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.