Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Hi I am trying to access the created by coloumn in item added event reciever.But when i debug it shows null value...below is the code

public override void ItemAdded(SPItemEventProperties properties)
{
   var CreatedBy = (string)properties.AfterProperties["Author"];
   // ....
}
share|improve this question

2 Answers 2

up vote 5 down vote accepted

Try using ListItem instead of AfterProperties

var CreatedBy = (string)properties.ListItem["Author"];

I believe the AfterProperties are for the synchronous events (end in ING - e.g. Adding, Deleting, etc.)

Furthermore you can get an SPUser object from this. Refer to the following site for details on how that might be done. Once you have an SPUser object you have access to all sorts of useful properties such as Name, Email, and more.

share|improve this answer
    
I i am getting the CreatedBy value as 9;#domain/username ..i am little confuse as to from where the value 9;# is coming from? –  spStacker Jan 24 '12 at 22:34
3  
A user field like that is essentially a lookup to the users list within the SharePoint Site Collection. 9 is the id of the user in the list, the ;# is a separator (and is the syntax used for all lookup fields) and domain\username is the value of the lookup. –  SpartanDonut Jan 24 '12 at 22:38
    
hi, tyler it is the look up field..thanks! –  spStacker Jan 24 '12 at 22:41
2  
@spStacker you can parse lookup field by using following code fragments: var id = new SPFieldLookupValue(fieldValue).LookupId and var value = new SPFieldLookupValue(fieldValue).LookupValue –  Andrey Markeev Jan 24 '12 at 22:42
    
No Problem! I updated my answer with a link on how you can get an SPUser object from that value as well. –  SpartanDonut Jan 24 '12 at 22:42

are you trying to access the value in the specific field? if so, try something like this:

using (SPWeb web = SPContext.Current.Web)
            {
                SPList list = web.Lists["yourListHere"];
                SPListItemCollection items = list.GetItems();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.