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.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI 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.
You can retrieve the system account by SPSite property
SPContext.Current.Site.SystemAccount
Basicaly EnsureUser method uses logon name (Domain\User_Alias) of the user.
i guess you are looking for some api to resolve inputs. try this utility method:
Microsoft.SharePoint.Utilities.SPUtility.ResolvePrincipal
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: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.resolveprincipal.aspx
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?