Get SPUser Information for the Document Creator

While working on creating a SharePoint 2007 event handler I needed to get the login name for the creator of the document I was trying to update. This is the code I snagged from a blog article which worked.

SPSite oSite = new SPSite("Your site URL");
SPList oList = oSite.OpenWeb().Lists["Your list name"];
SPListItem oItem = oList.GetItemById("Item ID");
string userValue = oItem["Created By"].ToString();
int index = userValue.Index Of(';');
int id = Int32.Parse(userValue.Substring(0, index));
SPUser itemCreator = oSite.OpenWeb().SiteUsers.GetByID(id);  

After using that information I could then call:


Which produces the users login name in the following format "DOMAIN\User".


Popular posts from this blog

Add User As Local Administrator On Domain Controller

Calling Dataverse Web API in PowerShell using Client Credentials

Windows Server 2008R2 VMs Shut Down After 1 to 2 Hours