0

I have an application page with Sharepoint ClientPeoplePicker control on it. I need to get the SPUser object for each of the resolved picker entities. Using SPWeb.EnsureUser method is out of the question (I've already read many articles about that). I actually need to know if the entities are users of the current SPWeb.

Any help how to achieve that will be appreciated.

1 Answer 1

2
using (SPSite site = new SPSite("http://MySite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    // Make sure the current user can enumerate permissions.
                    if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
                    {
                        // Specify the permission to check.
                        SPBasePermissions permissionToCheck = SPBasePermissions.ManageLists;

                        // Check the permissions of users who are explicitly assigned permissions.
                        SPUserCollection users = `PeoplepickerUsers`;
                        foreach (SPUser user in users)
                        {
                            string login = user.LoginName;
                            if (web.DoesUserHavePermissions(login, permissionToCheck))
                            {
                                Console.WriteLine("{0} is part of the SPWeb",login);
                            }
                        }
                    }
                }
            }

Stolen and edited from http://msdn.microsoft.com/en-us/library/ms441848.aspx You have to edit it with your peoplepicker entities and change the resultoutput but it should work.

Your Answer

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

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