I have an item event receiver for a specific content type that is used in a Pages library. I am using the event logger to debug it, and I can tell that whenever I edit a page and publish it, it fires 3 ItemUpdating and 3 ItemUpdated events. I am certain that no other pages are being saved in that specific time.
What is the cause of this and is there any way to "fix" it to trigger only 1 event per page publish?
Alternatively, is there any way to distinguish the last of the events (ie: page is now published or being published) from the others, so I don't end up running my code three times?
As it turns out, it was because the page was actually being saved 3 times when a user clicks "Publish":
The document is saved.
The document is checked in.
The document is published.
Each of these triggers an ItemUpdated and ItemUpdating event.
Use the DisableEventFiring() method to prevent any other events from firing. Just remember to enable it again via EnableEventFiring(). Hope this helps.
Related
I found a way to copy the attachments of a list item from one to another, therefore I used this code:
Sharepoint Online: Copy attachment of list item to a new item using Client object model
Now I have a new problem: I have an ItemUpdating & ItemUpdated event receiver, which listen both to my list, where the attachments are copied to. I want to prevent them from firing before all the attachments are copied. Actually the events are called when I save the list file (as I have to save before I'm able to copy the attachments!), but this should be avoided. Is there a possibility to "pause" the event receivers for this item until the attachments are copied? I need to realize it with the client object model.
Is it one time requirement? If yes, then you can turn off event receiver Enable/Disable Event receiver on list for sometime (till you completely process the attachment uploads) and then re-enable it. As CSOM doesn't support event receiver customization you have to use the web services to do this job on client side.
If it is real time scenario where you need to run this based on some criteria then I don't think you can do it as CSOM doesn't support it.
We would like to block the deletion of documents in a list based on some custom functionality.
What we have tried is to implement this in the ItemDeleting event. Where we set the cancel property of SPItemEventProperties to true when we do not want the user to be able to delete a document.
What happened was that the Delete option in the dropdown menu disapeared when the user was not allowed to delete a document. In a way this works, but the event is firing before the user actually tries to delete the document.
What is giving us problems is that the user can delete a document if they connect to the document library via MS Word 2003. In that case it does not appear that the ItemDeleting event fires.
Is there a way that we can get an event to fire and rollback the deletion when the document is deleted via MS Word.
Edit
Part of the problem could be that events do not fire in explorer view. Is there a fix for this "bug"?
ItemDeleting - An event that fires before an item is deleted.
more click here
I do not have sharepoint development environment right now so I can not give the exact answer but you can check on one thing that when user performs any action on a document from MS Word 2003 ItemUpdating event is fired. You can explore ItemUpdating event to see what is going to happen with the document and then deal with it accordingly.
We have a document list that contains Excel sheets, the documents that are in the list have to be processed. The processing code is triggered by the EventReceiver.
Until know we used the ItemCheckedIn event, but this isn't triggered when the user just saves a document from within Excel. I have tried to use the ItemUpdated event, but that doesn't seem to work either.
So I'm wondering whether there is an event that is triggered when a user saves the document from within Excel.
There are Before and After events when updating/adding list items. Here is a comprehensive list of all of those events:
Before Events
ItemAdding
ItemUpdating
ItemDeleting
After Events
ItemAdded
ItemUpdated
ItemDeleted
ItemAttachmentAdded
ItemAttachmentDeleted
ItemCheckedIn
ItemCheckedOut
ItemFileConverted
ItemFileMoved
ItemUncheckedOut
ItemAdded?
It's a little confusing since one event handler gets called when the document is initially saved and ItemUpdated gets called when you set any custom properties on the item, at least if you're using the default SharePoint web UI.
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.
}
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