Domanda

I am facing this issue where the following code is not working for one user (there may be more) i.e. Department field is coming as blank while for others it is working. If you see screenshots below, I am showing two users; user1 and user2 and for user1 it is working fine i.e. Department is being displayed but for user2 not Department is being displayed i.e. it is blank.

Code

 using (SPSite site = new SPSite(SPContext.Current.Site.RootWeb.Url))
 {
    string userName = System.Web.HttpContext.Current.User.Identity.Name.Replace("0#.w|", "");
    SPServiceContext context = SPServiceContext.GetContext(site);
    UserProfileManager profileManager = new UserProfileManager(context);
    UserProfile currentUserProfile = profileManager.GetUserProfile(userName);
    txtDepartment.Text = (string)currentUserProfile["department"].Value
    //in above code txtDepartment.txt is coming as blank for user2 but for user1 it is showing dept
}

User1 screenshot of User Profile Service
enter image description here

User2 screenshot of User Profile Service
enter image description here

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top