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.
Free SharePoint Development Tools Feature Stapling in SharePoint 2010 Part II