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.
Related
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.
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'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
I have a simple event handler with a ItemAdding event that changes a column value that I need in the ItemUpdated method. After uploading a word 2007 document (*.docx, *.pptx or xlsx) the value of the column is changed, but when I protect the document the value of the column disappears in the ItemUpdated method. This only happens for office 2007 documents, other files don't clear the value.
The event handler runs in a document library in MOSS 2007.
Thanks
We have the same issue. It appears that the properties from the list are added to the office 2007 doc, but only with the default values for the field on upload/creation. Once the item is edited we are experiencing that the office documents values are overriding the values set in our event handler.
We do not experience this when using an asynchronous event handler, but the asynchronous event handler has conflicts with updates on other threads with certain types of updates.
We have a support call active with Microsoft about this very issue. They acknowledge this is not
No results yet.
Try using an asychronous event handler (it runs a little bit later than the code that updates from the office document), but with caution.
UPDATE:
A workaround is setting the SPWeb.ParserEnabled to FALSE will remove the connection to the document properties which will stop the above behaviour. It prevents the list properties from being added to the office document.
When you upload an Office document into SharePoint, it tries to extract column from the document and promote them to the list.
Do, check if your doc has any attribute set. If this is the case, it can explain what you see.
Note: open advance document properties and delete all custom properties to be sure
I resolve the issue putting the SPWeb.ParserEnabled = false in the ItemUpdating method.
code:
properties.ListItem.Web.ParserEnabled = false;
Thanks all for help
Setting SPWeb.ParserEnabled = false does work, but there are effects! One very noticeable one is that it will break site and list templates. If SPWeb.ParserEnabled = false, and you save a list or site template, it's meta data is not set (Feature ID, Product Version, etc) and it will not be available in the list of templates to choose from. You might be able to get around this by resetting SPWeb.ParserEnabled=true during the itemUpdated event, but I haven't fully tested whether this will resolve all issues yet...
I am using VSTO 3.0 and the ribbon designer gives me a ribbon that is apparently shared across documents.
So if I have Document specific state( number of XML marked up tags say) that needs to show up in the ribbon( or a toggle button ) then all documents seem to share the ribbon instance
How can I fix this
TIA
You can use Application.DocumentChange event or Application.WindowActivate event.
The first is fired then you change the current active document, but in the arguments there's no information about that document, so it's difficult to work with because you'll have to figure that out.
The latter is similar and it's fired every time you change of window but in this case it passes the current active document as an argument, so it's easier to change the ribbon if you need to check the value of any document property. That worked for me.
Hook into an appropriate event (such as when the active document is changed) within the document model, and in that event invalidate the appropriate ribbon button (you'll need the id of the element from the original Ribbon xml you load).
Then, when the refresh state callback for that button occurs, you can update the caption/image/enabled as required.