Hello All,
In a follwing post we will see how to read User Profile Property values Programmatically.
In a below code snippet ,I am reading Birthday and Anniversary Custom Properties and some other Property values and updating in SharePoint List.
These values are reading for all the Users.
}
}
});
In a follwing post we will see how to read User Profile Property values Programmatically.
In a below code snippet ,I am reading Birthday and Anniversary Custom Properties and some other Property values and updating in SharePoint List.
These values are reading for all the Users.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSite = new SPSite(siteurl))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPServiceContext
serverContext = SPServiceContext.GetContext(oSite);
UserProfileManager
userProfileMangager = new UserProfileManager(serverContext);
IEnumerator profileEnumerator = userProfileMangager.GetEnumerator();
while (profileEnumerator.MoveNext())
{
string strBDate = string.Empty;
string strADate = string.Empty;
DateTime bDate;
DateTime aDate;
UserProfile
profile = profileEnumerator.Current as UserProfile;
//// Gets the Birthday Value.
////Birthday is the custom Property in my case
////Birthday is the custom Property in my case
if (!string.IsNullOrEmpty(
Convert.ToString(profile["Birthday"].Value)))
Convert.ToString(profile["Birthday"].Value)))
{
bDate = Convert.ToDateTime(profile["Birthday"].Value);
strBDate =
bDate.ToString("m");
}
//// Gets the Anniversary Value.
////Anniversary is the Custom Property in my case
////Anniversary is the Custom Property in my case
if (!string.IsNullOrEmpty(
Convert.ToString(profile["Anniversary"].Value)))
Convert.ToString(profile["Anniversary"].Value)))
{
aDate = Convert.ToDateTime(profile["Anniversary"].Value);
strADate =
aDate.ToString("m");
}
////Reading Picture Value
////Reading Picture Value
if (!string.IsNullOrEmpty(
Convert.ToString(profile["PictureURL"].Value)))
Convert.ToString(profile["PictureURL"].Value)))
{
oListItem["ProfilePic"] = Convert.ToString(profile["PictureURL"].Value);
}
//// Reading Department Value
//// Reading Department Value
oListItem["Department"]
=
Convert.ToString(profile["Department"].Value);
Convert.ToString(profile["Department"].Value);
//// Reading Designation Value
oListItem["Designation"]
=
Convert.ToString(profile["Title"].Value);
Convert.ToString(profile["Title"].Value);
SPUser user = oWeb.EnsureUser(Convert.ToString(profile.DisplayName));
}}
}
});
gud
ReplyDelete