I want to retrieve a SPUser object by Login Name in C#.
In my program, I got a DataTable from the SPListItemCollection and trying to get a SPUser Object in a foreach loop.
Here is the code snippet which shows how I am trying to get the SPUser
SPUser usera = new SPFieldUserValue(web, Convert.ToString(dr["OnlyUser"])).User;
but i got an error message about:
Value does not fall within the expected range
The error occurs because SPFieldUserValue require a specific format ([int];#[domain]\[username]). I failed because it returns the login name only from the DataTable.
Therefore, does anyone know how to get spuser obj by loginName without using SPWeb.EnsureUser() because this will add user to site if not already added.