0

I have to read data from an external source which contains names inside an XML-structure.

I have to map these names to users from an active directory. This is part of the code:

foreach (SPUser user in site.RootWeb.Users.Cast<SPUser>().Where(user => user.Name.Equals(displayName)))
    {
        ret = user.ID;
        return;
    }
    foreach (SPGroup group in site.RootWeb.Groups)
    {
        foreach (SPUser groupUser in group.Users)
        {
            if (groupUser.IsDomainGroup)
            {
                bool reachedMaxCount;
                using (SPWeb web = site.RootWeb)
                {
                    string adGroup = groupUser.LoginName;
                    SPPrincipalInfo[] users = SPUtility.GetPrincipalsInGroup(web, adGroup, limit, out reachedMaxCount);
                    if (users != null)
                    {
                        foreach (SPPrincipalInfo userPrinciple in users)
                        {
                            if (userPrinciple.DisplayName.Equals(displayName))
                            {
                                    ret = site.RootWeb.EnsureUser(userPrinciple.LoginName).ID;
                                    return;
                            }
                        }
                    }
                }
            }
        }
    }
});
return ret;

Because we have to map the user only by his name this can lead to problems, which did: One user was twice inside the active directory.

We deleted the "bad" one inside the active directory. But while this user cannot be seen anymore in SharePoint, the code above still collects that deleted user and is able to save it as a value from a "people picker" field.

How can this be solved?

1 Answer 1

1

There is a list for the site collection called the user information list. Here is an old post talking about it: http://zimmergren.net/technical/sharepoints-hidden-user-list-user-information-list

Basically, when a user is added into SharePoint site, the site collection for which the site resides in adds an entry for the user based on the current AD information. Now if you have user profile's setup with a sync, then the information in the user information list is updated with information from the user profile on a regular basis (every hour maybe?).

So even though you have deleted the user from AD, the user still exists in the user information list because at one time he was added to the site or visited the site and thus can still be selected from the people picker. You need to just delete the user from the user information list and you should be good to go.

Here is another post talking about how to delete a user using the UI: http://www.sharepointfire.com/MyBlog/2013/10/remove-users-from-user-information-list/

And another post describing almost your exact situation: http://sharepointrelated.com/2012/10/11/remove-bulk-users-from-user-information-list-people-picker/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.