If you read my article on this (http://spstips.blogspot.com/2006/09/synchronous-add-list-event-itemadding.html) you will find that Microsoft did this by design. In ItemAdding you dont get access to the item at all. Please join me in telling them to change it!
Ishai Sagi
www.spstips.blogspot.com
Frank,
No, you can't. Most list types return "null" for "AfterProperties" in the "ItemAdding" event (read about this in my blog - microsoft acknowledged it is by design)
Ishai,
Please try this:
public class clsBDC : SPItemEventReceiver{
public override void ItemAdding(SPItemEventProperties properties){
SPItemEventDataCollection b = properties.AfterProperties;properties.ErrorMessage = b[
"Title"].ToString();properties.Cancel =
true;}
}
This works for me. MSDN says about AfterProperties: Gets a hash table of properties consisting of string/value pairs that correspond to fields in the SPItem object after the event occurred.
Frank
Frank,
I am trying to get the curreom ErrorMessage to display but the only message that show is the generic "The data source control failed to execute the insert command." message on the generica Sharepoint error page.
how did you get it to show up correctly?
Hi,
I accessed the values of various list fields by "properties.AfterProperties["<field name>"]". We have to take care that here we have to give field's "Internal Name" e.g. if a field name is "Display Name" then its internal name would be "Display_x0020_Name". This internal name you can see in query string after clicking the field's name in list setting page i.e. edit the column.
But I am running into different problem that after setting properties.Cancel = true; and properties.ErrorMessage = "some message";, I get WSS standard error page (when user clicks "OK" button on NewForms.aspx page) showing the error message what I set but after that user is not able to continue his work. On each action e.g. going back to list form by clicking "Back" button of browser again shows "Unexpected error" page. Then the only solution is that user has to open a new browser and continue his work. Its annoying.
Please help.
Thanks.
Ashish