Can find user in peopleeditor but not in web?
-
09-12-2019 - |
Question
I want to assign the value from a peopleeditor control to a user field in C#.
I have a resolved entity in the people editor, but when passing the SPUserId into the SPFieldUserValue constructor along with the RootWeb (or even current web), the uservalue is null (i.e. it can't find the user). Is there a way of searching the active directory/the same place the people editor searches for this user as opposed to a SharePoint web?
Thanks a lot.
Solution
What you are probably missing is a call to EnsureUser, which will create the user if they haven't already visited the website; they don't exist within SharePoint if they haven't been to the website or had permissions explicitly set. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx
OTHER TIPS
You need to look to the site instead of the web to find users. Users and groups are all site objects.