Home > MOSS, SharePoint 2007, c# > Custom UserProfile Property Class for SharePoint

Custom UserProfile Property Class for SharePoint

I had a recent project where I needed to bind to the properties in the sharepoint userprofile collection. I found the easiest method was to create an object that contains properties that use the PropertyConstant enumerator to return values from the UserProfile object. It may not be the cleanest, but it let me bind a list of these to a grid, which was what I needed to do.

[Serializable]
 public class UserProfilePropertyObject
 {
 private UserProfile _userProfile = null;

 public UserProfilePropertyObject(UserProfile userProfile)
 {
 _userProfile = userProfile;
 }

 public string FullName
 {
 get { return LastName + ", " + FirstName; }
 }
 public string AccountName
 {
 get
 {
 return (_userProfile[PropertyConstants.AccountName].Value ?? "N/A").ToString();
 }
 }
 public string FirstName
 {
 get
 {
 return (_userProfile[PropertyConstants.FirstName].Value ?? "N/A").ToString();
 }
 }
 public string LastName
 {
 get
 {
 return (_userProfile[PropertyConstants.LastName].Value ?? "N/A").ToString();
 }
 }
 public string Username
 {
 get
 {
 return (_userProfile[PropertyConstants.UserName].Value ?? "N/A").ToString();
 }
 }
 public string WorkPhone
 {
 get
 {
 return (_userProfile[PropertyConstants.WorkPhone].Value ?? "N/A").ToString();
 }
 }
 public string Office
 {
 get
 {
 return (_userProfile[PropertyConstants.Office].Value ?? "N/A").ToString();
 }
 }
 public string Department
 {
 get
 {
 return (_userProfile[PropertyConstants.Department].Value ?? "N/A").ToString();
 }
 }
 public string Title
 {
 get
 {
 return (_userProfile[PropertyConstants.Title].Value ?? "N/A").ToString();
 }
 }
 public string Manager
 {
 get
 {
 return (_userProfile[PropertyConstants.Manager].Value ?? "N/A").ToString();
 }
 }
 public string AboutMe
 {
 get
 {
 return (_userProfile[PropertyConstants.AboutMe].Value ?? "N/A").ToString();
 }
 }
 public string PersonalSite
 {
 get
 {
 return (_userProfile[PropertyConstants.PersonalSpace].Value ?? "N/A").ToString();
 }
 }
 public string Picture
 {
 get
 {
 return (_userProfile[PropertyConstants.PictureUrl].Value ?? "N/A").ToString();
 }
 }
 public string Website
 {
 get
 {
 return (_userProfile[PropertyConstants.WebSite].Value ?? "N/A").ToString();
 }
 }
 public string PublicSiteRedirect
 {
 get
 {
 return (_userProfile[PropertyConstants.PublicSiteRedirect].Value ?? "N/A").ToString();
 }
 }
 public string DottedLineManager
 {
 get
 {
 return (_userProfile[PropertyConstants.Dottedline].Value ?? "N/A").ToString();
 }
 }
 public string Responsibilities
 {
 get
 {
 return (_userProfile[PropertyConstants.Responsibility].Value ?? "N/A").ToString();
 }
 }
 public string Skills
 {
 get
 {
 return (_userProfile[PropertyConstants.Skills].Value ?? "N/A").ToString();
 }
 }
 public string PastProjects
 {
 get
 {
 return (_userProfile[PropertyConstants.PastProjects].Value ?? "N/A").ToString();
 }
 }
 public string Interests
 {
 get
 {
 return (_userProfile[PropertyConstants.Interests].Value ?? "N/A").ToString();
 }
 }
 public string Schools
 {
 get
 {
 return (_userProfile[PropertyConstants.School].Value ?? "N/A").ToString();
 }
 }
 public string SIPAddress
 {
 get
 {
 return (_userProfile[PropertyConstants.SipAddress].Value ?? "N/A").ToString();
 }
 }
 public string Birthday
 {
 get
 {
 return (_userProfile[PropertyConstants.Birthday].Value ?? "N/A").ToString();
 }
 }
 public string MySiteUpgrade
 {
 get
 {
 return (_userProfile[PropertyConstants.MySiteUpgrade].Value ?? "N/A").ToString();
 }
 }
 public string DontSuggestList
 {
 get
 {
 return (_userProfile[PropertyConstants.DontSuggestList].Value ?? "N/A").ToString();
 }
 }
 public string HireDate
 {
 get
 {
 return (_userProfile[PropertyConstants.HireDate].Value ?? "N/A").ToString();
 }
 }
 public string LastColleagueAdd
 {
 get
 {
 return (_userProfile[PropertyConstants.LastColleagueAdded].Value ?? "N/A").ToString();
 }
 }
 public string OutlookWebAccessURL
 {
 get
 {
 return (_userProfile[PropertyConstants.OutlookWebAccessUrl].Value ?? "N/A").ToString();
 }
 }
 public string Assistant
 {
 get
 {
 return (_userProfile[PropertyConstants.Assistant].Value ?? "N/A").ToString();
 }
 }
 public string WorkEmail
 {
 get
 {
 return (_userProfile[PropertyConstants.WorkEmail].Value ?? "N/A").ToString();
 }
 }
 public string MobilePhone
 {
 get
 {
 return (_userProfile[PropertyConstants.CellPhone].Value ?? "N/A").ToString();
 }
 }
 public string Fax
 {
 get
 {
 return (_userProfile[PropertyConstants.Fax].Value ?? "N/A").ToString();
 }
 }
 public string HomePhone
 {
 get
 {
 return (_userProfile[PropertyConstants.HomePhone].Value ?? "N/A").ToString();
 }
 }
 public Guid ID
 {
 get
 {
 return _userProfile.ID;
 }
 }

 }
Categories: MOSS, SharePoint 2007, c# Tags:
  1. Srini
    September 7th, 2009 at 06:29 | #1

    Nice.. Suppose if user has one custom property like internal phone, how do we access it ???
    I’ve tried accessing it by using PropertyConstant but am not getting the custom property… Plz suggest..

  2. Michael Bell
    October 14th, 2009 at 08:36 | #2

    @Srini OH wow… it’s been awhile man. I’m going to have to punt on that and say… goooooooooogle will have the answer.!

  3. November 1st, 2010 at 06:13 | #3

    Hey Srini,

    Did u able to solve you issue?? I am newbie and stuck here, spend almost two days but not able to solve this problem. Please let me know if u done with this. Thanks

  1. No trackbacks yet.