0

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?

1
  • Items in the list is being added from visual web part.
    – users1100
    Commented Oct 7, 2013 at 6:37

5 Answers 5

2

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.

2
  • @users1100, Did you get the values in ItemUpdated.? Commented Oct 7, 2013 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
    Commented Oct 8, 2013 at 4:22
0

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/

1
  • Tried using internal name also but still all values are null
    – users1100
    Commented Oct 7, 2013 at 5:23
0

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

2
  • Thank you for reply sir, tried your way also but not working
    – users1100
    Commented Oct 7, 2013 at 5:49
  • Can you try in item adding? let me know if it gives values there.
    – Ishan
    Commented Oct 7, 2013 at 5:59
0

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.

3
  • Yes, I am sure that the event is firing because I debugging it in Visual Studio by attaching process w3wp :-)
    – users1100
    Commented Oct 7, 2013 at 6:03
  • Whether your properties has values for any columns in the list?
    – Suren
    Commented Oct 7, 2013 at 6:49
  • try setting EventFiringEnabled = false; before base.ItemAdded(properties); and EventFiringEnabled = true; at the end of the ItemAdded function.
    – Suren
    Commented Oct 7, 2013 at 6:54
0

Try with the

properties.AfterProperties["InternalColumnName"]

Ref: List Before and After properties

Hope this helps you.

4
  • Tried AfterProperties also sir.
    – users1100
    Commented Oct 7, 2013 at 6:09
  • The values to the list is being added via visual web part, can it create problem
    – users1100
    Commented Oct 7, 2013 at 6:28
  • @users1100, are you getting the ID value for properties.ListItemId ? Commented Oct 7, 2013 at 6:54
  • Yes I can get item using the ListItemId
    – users1100
    Commented Oct 7, 2013 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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