I am working on developing a server side event receiver inside sharepoint on-premises farm 2013. Inside the code i have the following, which will retrieve a string from a drop down list column representing a user name such as (User.A). the drop down list column name is OrderAssignToApprover , then I will convert the string to SPUSer:-
string approver = currentItem["OrderAssignToApprover"].ToString();
SPUser spUser = properties.Site.RootWeb.EnsureUser(approver);
now for certain user only the EnsureUser
will return this exception:-
The specified user User.A could not be found.
so i thought that the user is deleted or is disabled, but i try adding the user to a sharepoint security group and assign it to a people or group field, and i was able to do so without any problem.. so seems the user is valid, but not sure why EnsureUser
will return an exception..
EDIT.
Now i checked with our system admins and seems the user's account was disabled inside the AD. so this means that EnsureUser
will not work on accounts which have been disabled. so now my question should be if there is a way to convert a string (representing a user's login name) to SPUser
object, while the username's account is disabled inside AD?? seems EnsureUser
will not support this.. so are there other function or workarounds?