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

I have created an event receiver which will be executing after the item is added to the list.

I want to make the sub site based on the values entered in the list.

My event receiver code is:

    public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);

        SPListItem item = properties.ListItem;
        string url = Convert.ToString(item[FieldNames.Url]);
        string title =Convert.ToString(item[FieldNames.ProjectName]);
        string desc = Convert.ToString(item[FieldNames.AboutProject]);
        SPWeb web = properties.Site.AllWebs.Add(url, title, desc, 1033, "Lf.Int#4", false, false);
        web.Dispose();            
    }

In code FieldName class properties are for getting the internal names of fields.

I debugged the program and found url="" title="" desc="" i.e. I am not getting any value through item object. All things are null.

What am I missing?

share|improve this question
    
Items in the list is being added from visual web part. –  users1100 Oct 7 '13 at 6:37
add comment

5 Answers 5

up vote 2 down vote accepted

Just to be sure, try to get the values from ItemUpdated event. Maybe the reason why that the values are not available is because they aren't exist yet.

share|improve this answer
    
Thank you for help –  users1100 Oct 7 '13 at 8:34
    
@users1100, Did you get the values in ItemUpdated.? –  Karthik Jaganathan Oct 7 '13 at 10:38
    
Yes,there was matter with the item adding. I added item values from visual web part and while adding event I used ListItem item = list.AddItem(); instead I did item=list.Items.Add() –  users1100 Oct 8 '13 at 4:22
add comment

It seems you are not using internal names of the fields in the code. The follwoing post shows how to get internal names of the fields:

http://www.idubbs.com/blog/2012/finding-internal-names-for-sharepoint-list-columns/

share|improve this answer
    
Tried using internal name also but still all values are null –  users1100 Oct 7 '13 at 5:23
add comment

Remove base.ItemAdded(properties); and try properties.ListItem["InternalName"]

share|improve this answer
    
Thank you for reply sir, tried your way also but not working –  users1100 Oct 7 '13 at 5:49
    
Can you try in item adding? let me know if it gives values there. –  Ishan Oct 7 '13 at 5:59
add comment

You can check using properties.ListTitle to confirm whether this event fires when you add entry into your list. Because this event is common and it will be called for every list.

share|improve this answer
    
Yes, I am sure that the event is firing because I debugging it in Visual Studio by attaching process w3wp :-) –  users1100 Oct 7 '13 at 6:03
    
Whether your properties has values for any columns in the list? –  suren Oct 7 '13 at 6:49
    
try setting EventFiringEnabled = false; before base.ItemAdded(properties); and EventFiringEnabled = true; at the end of the ItemAdded function. –  suren Oct 7 '13 at 6:54
add comment

Try with the

properties.AfterProperties["InternalColumnName"]

Ref: List Before and After properties

Hope this helps you.

share|improve this answer
    
Tried AfterProperties also sir. –  users1100 Oct 7 '13 at 6:09
    
The values to the list is being added via visual web part, can it create problem –  users1100 Oct 7 '13 at 6:28
    
@users1100, are you getting the ID value for properties.ListItemId ? –  Karthik Jaganathan Oct 7 '13 at 6:54
    
Yes I can get item using the ListItemId –  users1100 Oct 7 '13 at 7:01
add comment

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.