0

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

  • Is this 2013 on premise? Did you chk debugging the code if it is on premise. this way u can be sure whether the event receiver id firing or not – Unnie Apr 4 '14 at 12:49
  • Hi Unnie, Yes it's on premise. But because i'm deploying this to the content type hub, I cannot really test why it's not firing. When I see the ULS logs, it said it's locked by myself. (i think because the document is still open in word) If i close or save the document, it doesn't fire too. – deefken Apr 4 '14 at 12:52
  • I saw in the ULS logs the following error: "<nativehr>0x80071772</nativehr><nativestack></nativestack>The file "filename..." is locked for shared use by "my own user..." – deefken Apr 4 '14 at 12:59
1

This issue is solved. For people who have the same problem, the answer is extremely simple.

Instead of using currentItem.Update() at the end of the event receiver, just use currentItem.SystemUpdate() and it will update even the document is still open in your Office client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.