I have a weird problem. I created a content type in Visual Studio 2012 for SharePoint 2013 with some metadata fields, a document template (word) and deployed it to the content type hub. The content type is successfully published to the subscribed site collections including the document template, and i can perfectly add this content type to a document library and add documents based on this document template.
I also added an event receiver to the content type to set some default values based on some conditions (for example if field A is empty, set field B to 'some text'.
All of this works perfectly when I update item properties (using the event receiver ItemUpdated and/or ItemUpdating). And now my problem...
When I add a new item using Microsoft Word 2010, and I leave field A empty (so he should set field B to 'some text', this don't happen.
I tried to use the event receivers ItemAdded, ItemAdding, ItemUpdated, ItemUpdating but it looks like non of them fire.
After doing some research, it looked like the event receiver fire, but he see the document is locked by a user (my own account) in Word when he tries to change the field value.
Is there a step or thing I need to do to let this field change or other event fire? Or is there a property, parameter or method I need to do to 'force' this?
My XML code is like this:
<Receiver>
<Name>EventReceiverItemAdded</Name>
<Type>ItemAdded</Type>
<SequenceNumber>10001</SequenceNumber>
<Assembly>My project assembly name</Assembly>
<Class>My project class</Class>
</Receiver>
My event receiver code (only an example, I also have the same for ItemUpdated,...
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPListItem currentItem = properties.ListItem;
if (currentItem["field A"] == null)
{
currentItem["fieldB"] = "some text";
}
currentItem.Update();
}
Any help is welcome!
Thanks in advance!
Kind regards,
Davy