Sep 19, 2009

How to programmatically get the Profile of the user from the MySite profile page

When we visit the MySite,there are two types of pages ,one is default page of the current user and other is the person.aspx which points to the profile of the user .This person.aspx can be of current logged in user or can be of any visited user.
So to get the profile of the user (current logged or visited user) programmatically ,we use "ProfilePropertyLoader sharepoint object .This works only on profile of the user and not on the home page.

This is the code below to load the profile
-------------------------------------------

ProfilePropertyLoader loader = ProfilePropertyLoader.FindLoader(this.Page);

if (loader != null)

{

Microsoft.Office.Server.UserProfiles.UserProfile profile = loader.ProfileLoaded;

if (profile != null)

{

String AccName = Convert.ToString(profile["AccountName"].Value, CultureInfo.InvariantCulture);

}

}

-----------------------------------------

Thus u can get the all the properties from the profile loader

Enjoy!!!

No comments:

Post a Comment