Domanda

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?

È stato utile?

Soluzione

try with EnsureUser

SPUser user = web.EnsureUser(userValue.LoginName);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top