The enigma of software development.

Retrieving the current user in SharePoint 2010 object model

This is a really simple code snippet to obtain the current user using the SharePoint object model.

using (SPWeb spweb = SPContext.Current.Web) {
SPUser oUser = spweb.CurrentUser;
string Username = oUser.LoginName;
}

SPUser represents a user in SharePoint services. A new object (oUser) is created from the spweb property, currentUser. We can now access various other properties like LoginName, Name etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">