ItemAdded event not fire when adding multi items - sharepoint

I'm using a WebPart to add more than one list item at a time.
And I also have an EventReceiver to handle ItemAdded event on this list.
The problem is when the WebPart adding items, only first item's added item was caught by the EventReceiver.
Don't know the reason why. Can someone help me to explain this? Thanks.
I'm using SharePoint Online.

Can You post some code of your event receiver? Maybe the reason is that there is some kind of error thrown. Since ItemAdded is run asynchronously, you won't get any visual notification of error (Except maybe some sandbox quota rising faster, since it's SharePoint Online.).

Related

Event Handler Management / View list?

I've made an event handler on a list (with the ID of the custom list) with a feature. I activated the feature, but my Event Handler Code is never called (the ItemAdding method).
My question is if there is something that can tell me if the list I created is really tied up with my Event Handler? I've seen something on CodePlex but it was for MOSS, is there something available for WSS or "out of the box"?
I've found that you can use Sharepoint Manager :
http://www.codeplex.com/spm
You can browse to your list and check under "Event Receiver". If your Event Handler is there, then it should be tied up to your list.
In my case it's there but It's called for whatever reason.. I'll have to investigate on that.
UPDATE :
Well, it seems that when SharePoint raises an exception in an Event Handler, it doesn't write any error message and continue like nothing happened, so be sure to debug line by line to check if all your code is called!

sharepoint event receiver events not firing

I added a workflow to my document library (with a custom content type) and now my content types event receiver function itemcheckingin doesnt fire. Double checked my xml files and it's being properly refered to and other events (itemupdating, itemadding) are firing. Any ideas?
Have you tried programmtically pulling down a list of Event Receivers using something like SPList.EventReceivers and seeing if the correct events are bound to your receiver? Sometimes the XML files don't show exactly what the database is holding.
-Shaun
Is your list item definitely of the content type that has the registered event handler? It sounds like you might have created a new item of the workflow-containing content type where that content type does not have a handler for the event of interest. I guess I interpret your post as saying that you now have two content types -- one with the workflow and one with the event handler.
I second #SCMcDonnell's suggestion to go straight to the horse's mouth and see what event receivers are registered for your list item and its content type.
EDIT: Oh, I guess I initially missed your claim that other events are firing successfully. That makes my answer less likely. Still, I recommend that you go specifically retrieve the event receivers for the offending list item.
Does the list have force checkout on it?
If it does, then the checkin fires and ItemUpdated as well. See this KB article
http://support.microsoft.com/default.aspx/kb/939307
if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
//This is when the update event is triggered by check-in.
}
else
{
//This is triggered by events other than check-in action.
}

Registering SharePoint Event Receivers that are already registered

I am writing a web part against a list. The first thing I do in the web part is verify that my custom event receivers are registered on the list. If they are not, I register the programmatically.
I have noticed that if I try to register an event that is already registered, I get no errors and no “Extra” events are registered.
My question is: Would it be more efficient to just register the events each time the web part loads rather than iterating through each event in the event receiver list and doing compares to see if each of my event receivers are there?
Edit
About the Property bag suggestions. After thinking a bit more about it, this will not be a feasable solution. The reason that I am "verifying" that the receivers are there is because we have 3rd party webparts that are attached to the same list. These have, in the past, actually unregistered our custom receivers. Setting a flag in the property bag will just let me know that I have verified once, but won't tell me if they get removed by another.
The code that SharePoint uses to update an event receiver collection is obfuscated, so there's no way to know for sure. I would guess that the first step is a check similar to what you are doing manually. I'm inclined to go with what's easiest until you identify that performance is an issue, in which case I would set a flag on the list's RootFolder's property bag.
I unsure if this is best approach. I have seen a code that does something similar to your requirement. What it does is that once the EventHandler are added they stored a flag in the SPWeb Property Bag. Next time you just check the Property bag for the flag if it is there dont register the eventhandler . Refer this link for more information about the property bag. Final note you might need more permission to set the property bag value to SPWeb

ItemUpdating not showing changed values in SharePoint event receiver

I'm trying to find how a field's value has changed in an ItemUpdating event receiver. The particular field's display name and internal name is Regions.
As soon as ItemUpdating is hit, the value of the Regions field is identical for the following:
properties.AfterProperties["Regions"]
properties.BeforeProperties["Regions"]
properties.ListItem["Regions"].ToString()
I would expect the latter two to contain the old value but surely AfterProperties should be set correctly.
Does anyone know how I can obtain the changed value?
Update: The event handler is attached to a MOSS 2007 publishing Pages list.
I've had a lot of trouble with event handlers on publishing pages libraries. Think it comes from their being other event handlers on there already for publishing. I had better success with updating, can you change to that or do you need the sync event to block the change ?
Are you trying this in a List or Document Library ?
It will work Only on the Doc Lib Please refer to these
MSDN and another on same subject

ItemAdding never fired

I have a custom content type with two event handler attached : ItemAdded and ItemAdding.
The first one (ItemAdded) is fired without problem.
But the second one is never fire. I've attached the event using API et declarative way. But nothing change.
Do you have already get the same issue ?
Maybe you can use this tool to check wheather your event receivers are assigned correctly to the list where your content type is used:
http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/
Maybe you have a configuration error in your feature definition.
Look in the Event Logs. Mine, most of the time, will place an error entry in the Application event log.

Resources