views:

123

answers:

2

I have the login ID of that user. But in the code I want to convert that login name into SPUser Object. Can I convert LoginName(type string) to SPUser. Or is there any way to convert windows identity user token to SPUser. I am adding users to a spgroup(so does not exist on the site). All I have is windows user token.

Thanks

A: 
SPUser user = SPContext.Current.Web.Users["domain\\login"];
omlin
I am adding users to a group. So he dose not exist on the site.
sssreddy
so use EnsureUser, as described in CBono post
omlin
+2  A: 

Take a look at SPWeb.EnsureUser. From MSDN:

"Checks whether the specified login name belongs to a valid user of the Web site, and if the login name does not already exist, adds it to the Web site."

Used thusly:

SPUser newUser = SPContext.Current.Web.EnsureUser(@"domain\logonname");
CBono