SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a string "System Account", how can I convert the string into SPUser?

I've tried SPContext.Current.Web.EnsureUser("System Account") and also web.AllUser["System Account"] but hit error.

Please help, thank you in advanced.

share|improve this question
I've tried SPWeb.AllUsers.GetByID(userID).ID.ToString() and it solved my issue, I should have use userID instead of user name in string – sams5817 Apr 1 '12 at 18:41
up vote 4 down vote accepted

You can retrieve the system account by SPSite property


Basicaly EnsureUser method uses logon name (Domain\User_Alias) of the user.

share|improve this answer
thanks for your reply, what if I do not have Domain\User_Alias? I only have the welcome name in string format? is it still possible I validate and convert into SPUser? – sams5817 Mar 31 '12 at 8:50
I do not sure, but welcom name is not an unique name... if it is true, i think that it is not possible. – Alexander Mar 31 '12 at 8:58
One way is to loop through all siteusers, but this solution is a performance killer ( – Alexander Mar 31 '12 at 10:27

i guess you are looking for some api to resolve inputs. try this utility method:


it will return a SPPrincipal object, witch contains a "LoginName" property. then you can use SPWeb.EnsureUser(loginName) to get a SPUser object.

more infomation about this method:

share|improve this answer

Try this, should work

string strUser = “Shiva Bala”;

//(myWeb is your SPWeb object)

SPFieldUserValue flduserVal = new SPFieldUserValue(myWeb, strUser);

SPUser myUser = flduserVal.User;

plus can someone tell me how to do it if there is a domain user?

share|improve this answer
You can not pass the display name as argument to SPFieldUsesrValue constructor. This requires item value (e.g. "12#;Shiva Bala"). With respect to question, Basically, one need to pass Logon Name as parameter in EnsureUser method. And for fetching user, one should use "SPWeb.AllUsers.GetByID(loginName)". – Dipesh Bhanani Oct 23 '12 at 8:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.