Showing posts with label SPUser. Show all posts
Showing posts with label SPUser. Show all posts

Thursday, June 3, 2010

Get loginname of the Sharepoint user with username efficently

Share/Save/Bookmark

If you wonder how to get login name with user name programmatically in SharePoint then you are reading the right post.
We can do this by looping all the users of web and get the spuser that matches with the username or by simply using SPFieldUserValue like below,
using (SPSite site = new SPSite("http://sharepointcustomization.blogspot.com/"))
{
using (SPWeb web = site.OpenWeb())
{
SPFieldUserValue userValue = new SPFieldUserValue(web, "UserName");
if (userValue.User.LoginName == web.CurrentUser.LoginName)
{
//do something!
}
}
}

Subscribe