I've been trying to get all users from a SharePoint site collection site.
But some people that I can retrieve using people picker, I can't find from the code. And whene I try to get them using UserProfile user = userProfileMgr.GetUserProfile(targetAccountName), I get the exception:
An error was encountered while retrieving the user profile
List<String[]> users = new List<String[]>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
string targetAccountName = "virtualsp\\b.ferreirarocha";
using (SPSite site = new SPSite("http://sp2010devid/sites/EsercioWeekend/"))
{
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
try
{
// Retrieve and iterate through all of the user profiles in this context.
Console.WriteLine("Retrieving user profiles:");
UserProfileManager userProfileMgr = new UserProfileManager(serviceContext);
IEnumerator userProfiles = userProfileMgr.GetEnumerator();
while (userProfiles.MoveNext())
{
UserProfile userProfile = (UserProfile)userProfiles.Current;
users.Add(userProfile.MultiloginAccounts);
}
// Retrieve a specific user profile. Change the value of a user profile property
// and save (commit) the change on the server.
UserProfile user = userProfileMgr.GetUserProfile(targetAccountName);
Console.WriteLine("\nRetrieving user profile for " + user.DisplayName + ".");
user.DisplayName = "Pat";
user.Commit();
Console.WriteLine("\nThe user\'s display name has been changed.");
Console.Read();
}
catch (System.Exception e)
{
Console.WriteLine(e.GetType().ToString() + ": " + e.Message);
Console.Read();
}
}

0 commentaires:
Enregistrer un commentaire