Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Cant add listitems.....

  Asked By: Celia    Date: Aug 28    Category: Sharepoint    Views: 745

Any idea what is wrong with this code. I know it is firing as I can
see the message afterI cancel the event, but the item does not get
added to the list. all 3 columns are text. i have put the code in a try
catch and no exceptions are raised.


SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists["Temp User Assigned
Product Access"].Items;

SPListItem item = listItems.Add();

item["Title"] = "text";
item["UPF ID"] = "text";
item["User ID"] = "text";


item.Update();
properties.ErrorMessage = "i did fire!!!";
properties.Cancel = true;

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Linsey Bauer     Answered On: Aug 28

If I'm not mistaken cancelling the event  receiver also cancels the add
if you are using an ItemAdding event receiver.

 
Answer #2    Answered By: Ivy Salinas     Answered On: Aug 28

I am running it from a ItemUpdated event  reciever, and have removed
the cancel  and the item  is not added to the list  either.

 
Answer #3    Answered By: Kevin Davis     Answered On: Aug 28

Anytime you specify properties.Cancel = true; in an "ing" event, no
updates occur.

You can add/update listitems  in the "ing" and "ed" events. Instead of
item.Update(); try item.SystemUpdate();

Also, at the beginning of the event, execute:
this.DisableEventFiring();

At the end of the event, execute:
this.EnableEventFiring();

These commands manage the accidental firing  of events from actions
performed in your code.

 
Answer #4    Answered By: Meenakshi Khochar     Answered On: Aug 28

Can you fill me in a little more then about what you are trying to
accomplish? Are you adding another item  to the list  when an item is
updated? Or to a separate list? For what purpose?

 
Didn't find what you were looking for? Find more on Cant add listitems..... Or get search suggestion and latest updates.




Tagged: