Sunday, January 4, 2009

Modifying the person.aspx file to filter the display in sharepoint 2007

Person.aspx will use various query strings to load the desired person's profile

accountname User's account name, e.g. (DOMAIN\username)
guid The user's guid in SharePoint
sid The user's sid from Active Directory
preferredname Tries to find a match based on the displayName attribute from Active Directory
user Takes various iterations of display names or usernames and tries to resolve to a user, by redirecting to _layouts/SelectUser.aspx.


Open the Person.aspx to see what controls are being used and concentrate on the ProfileViewer (the control that displays Profile Property values).

<SPSWC:ProfileViewer id="ProfileViewer" ShowBusinessCardIfEmpty="false" runat="server" />


this ProfileViewer is inherited from ProfileUI, the InitControl will have the code:

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


this is the method call to get a loaded profile.
Now looking in to the ProfilePropertyLoader, will look for the object. If not found in the HttpContext.Items collection, that will create a new object.

The ProfilePropertyLoader has two properties that return a UserProfile object, ProfileCurrentUser (the profile for the browsing user) and ProfileLoaded (the profile of the user to be displayed, which may be the same as ProfileCurrentUser).


after getting to know the UserProfile object via ProfilePropertyLoader, create a filter web part, so that you could pass in filter or query values from the UserProfile to other web parts via Connections.

MSDN has a great article on creating a Filter provider web part, so follow that and add code to get user profile values and pass those into other web parts.

public ReadOnlyCollection<string> ParameterValues   
 { 
get
{
        // Get a reference to the ProfilePropertyLoader,
         // which contains the reference to the UserProfile 
         Microsoft.SharePoint.Portal.WebControls.ProfilePropertyLoader loader = Microsoft.SharePoint.Portal.WebControls.ProfilePropertyLoader.FindLoader(this.Page);  
        if (loader == null)  
       {  
          return null; 
        } 
       Microsoft.Office.Server.UserProfiles.UserProfile profile = loader.ProfileLoaded; 
  if (profile == null)  
    {  
           return null;  
       }  
       string thirdPartyAppUserID = (string)profile["ThirdPartyAppUserID"].Value; 
        if (string.IsNullOrEmpty(thirdPartyAppUserID))  
        {  
            return null; 
        }  
        List<string> thirdPartyAppUserIDList = new List<string>();  
       thirdPartyAppUserIDList.Add(thirdPartyAppUserID); 
         return new ReadOnlyCollection<string>(thirdPartyAppUserIDList);  
    }   }


source:
http://www.sharepointblogs.com/toth/archive/2008/05/30/filtering-data-on-the-mysite-profile-page-person-aspx.aspx

No comments:

Post a Comment