Saturday, December 6, 2014

How to get Current login user SharePoint?

SPSite site = new SPSite(http://server); SPWeb myweb = site.OpenWeb(); SPUser found = myweb.AllUsers.GetByID(1);

SPContext.Current.Web.CurrentUser

Web web = clientContext.Web; clientContext.Load(web); clientContext.ExecuteQuery(); //Get the site name. siteName = web.Title; //Get the current user. clientContext.Load(web.CurrentUser); clientContext.ExecuteQuery(); currentUser = clientContext.Web.CurrentUser.LoginName;
$().SPServices({ operation: "GetUserInfo",
async: false,
userLoginName: $().SPServices.SPGetCurrentUser(),
completefunc: function (xData, Status) {
$(xData.responseXML).find("User").each(function() {
curUserId = $(this).attr("ID");
curUserName = $(this).attr("Name");
curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name");
});
} }); alert(curUserId);
$web = Get-SPWeb "http://testurl/" $user = $web.EnsureUser("domainname\Raghu") $id = $user.ID

2 comments: