Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Receiver for Document Library

I'm trying to update one of the properties of a word document from an event receiver.

I'm handling it with the ItemAdded event and updating the property as is:

// Modify property
DisableEventFiring();
properties.ListItem.File.CheckOut();
properties.AfterProperties[HelloWorldInternalFieldName] = "Hello World!";
properties.ListItem.UpdateOverwriteVersion();
properties.ListItem.File.CheckIn("Updating Property!");
properties.ListItem.SystemUpdate();
EnableEventFiring();

I'm getting an exception when I'm trying to modify it and it is saying:

The event does not support change of properties.

Does anyone have an idea why and why I cannot update the property after I save the document to the document library in Word?

Thanks!

like image 864
LB. Avatar asked Feb 20 '09 01:02

LB.


People also ask

What is an event receiver?

Event Receiver is a feature in SharePoint to handle events that are triggered when an action happened on SharePoint objects. One example is when you need to notify a person when a file is uploaded to a document library.

What are the type of event receivers available in SharePoint list?

There are two types of Event Receiver in SharePoint, Synchronous Event Receiver. Asynchronous Event Receiver.

How do I add an event receiver to a SharePoint list?

Select event receiver and enter the title of the event receiver. Click the Add button. Select List Item Events in the type of event receiver and select the custom list option from the event source. Then select "an item was added" in events and click Finish.


1 Answers

I know what the problem is:

AfterProperties is read-only in -"ed" events. You can just modify the list item:

properties.ListItem["HelloWorldInternalFieldName"] = "Hello World!";
like image 141
LB. Avatar answered Sep 24 '22 12:09

LB.