I am trying to get a user's information off of SharePoint. I can see the user's information through the UI when I click their name. I can add them to groups and sites freely. But no matter what I try, I cannot get the user's information through code.
Below is a portion of my code that cannot find the specific user. I can find any other user.
SPUser userInGroup=...; //This is the user
Microsoft.SharePoint.SPServiceContext context = Microsoft.SharePoint.SPServiceContext.GetContext(site);
Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
Microsoft.Office.Server.UserProfiles.UserProfile profile = profileManager.GetUserProfile(userInGroup.LoginName);
foreach (var property in profile.Properties)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("{0}", property.DisplayName, property.Name, profile[property.Name].Value);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("[{1}]", property.DisplayName, property.Name, profile[property.Name].Value);
Console.ForegroundColor = ConsoleColor.White;
Console.Write(":\t");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{2}", property.DisplayName, property.Name, profile[property.Name].Value);
}
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("----\t----\t----\t----\t----");
Console.ResetColor();
Am I pulling from AD or SP. It looks like I am pulling from SP, but if I go into User Profile Service Application in Central Admin and search for the user, I can't find anything.