Moss user profile (1): Get and traverse

Source: Internet
Author: User

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

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.