i have class UserProperties.cs in that i write some code=> public UserProperties(SPUser currentUser) { using (var site = new SPSite(SPContext.Current.Web.Url)) { try { LoadUserProperties(site, currentUser); } catch (Exception exp) { LoggingService.LogError("Failed to get " + currentUser.Name + "'s information", exp); } } }
private void LoadUserProperties(SPSite site, SPUser user) { CurrentUser = user; var userLoginName = CurrentUser.LoginName;
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
var profileManager = new UserProfileManager(serviceContext);
var userProfile = profileManager.GetUserProfile(userLoginName);
Profile = userProfile;
//object value
var currentuserHireDate = userProfile[PropertyConstants.HireDate].Value != null
? userProfile[PropertyConstants.HireDate].Value.ToString()
: "";
CurrentJobFunction = userProfile[PropertyConstants.Department].Value != null
? userProfile[PropertyConstants.Department].Value.ToString()
: "";
CurrentJobFunctionUrl = GetJobFunctionUrl(CurrentJobFunction);
CurrentLocation = userProfile[PropertyConstants.Office].Value != null
? userProfile[PropertyConstants.Office].Value.ToString()
: "";
CurrentLocationUrl = GetLocationUrl(CurrentLocation);
PrefferedName = userProfile[PropertyConstants.PreferredName].Value != null
? userProfile[PropertyConstants.PreferredName].Value.ToString()
: "";
ProfilePicture = userProfile[PropertyConstants.PictureUrl].Value != null &&
!userProfile[PropertyConstants.PictureUrl].Value.ToString().Equals(string.Empty)
? userProfile[PropertyConstants.PictureUrl].Value.ToString()
: "/_layouts/15/images/PersonPlaceholder.200x150x32.png";
MyProfileUrl = userProfile.PersonalSite != null ? userProfile.PersonalSite.Url : "#";
if (userProfile[PropertyConstants.PreferredName].Value != null)
{
FirstName = userProfile[PropertyConstants.FirstName].Value != null &&
!userProfile[PropertyConstants.FirstName].Value.ToString().Equals(string.Empty)
? userProfile[PropertyConstants.FirstName].Value.ToString()
: userProfile[PropertyConstants.PreferredName].Value.ToString();
LastName = userProfile[PropertyConstants.LastName].Value != null &&
!userProfile[PropertyConstants.LastName].Value.ToString().Equals(string.Empty)
? userProfile[PropertyConstants.LastName].Value.ToString()
: string.Empty;
}
}
//I have NewHire webparts in NewHire.cs i write some code to test can i access all user properties ->
private HtmlGenericControl GetHtmlForNewHires() { var userproperties = new UserProperties();
var url = userproperties.MyProfileUrl;
if (string.IsNullOrEmpty(url))
url = "#";
var s = userproperties.FirstName;
var article = new HtmlGenericControl("article");
article.InnerHtml = s;
}
//But i am not getting user properties i have 5 user profiles. and also also i want to get user having hire date is within last 30 days
0 commentaires:
Enregistrer un commentaire