SPFieldUserValue.User property is null for few users only
-
22-12-2020 - |
Pergunta
SPFieldUserValue userValue = new SPFieldUserValue(SPContext.Current.Web, DisplayName);
SPUser user = userValue.User;
I wanted to fetch user from site (web) using display name and display that created by user name on a page.
But for few users, userValue.User
is null,
If I change code to
SPUser user = SPContext.Current.Web.EnsureUser(userValue.LookupValue)
it is working as expected.
My concern is why userValue.User
is null for only few users?
Solução
try with EnsureUser
SPUser user = web.EnsureUser(userValue.LoginName);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange