Dienstag, 27. März 2007

Sharepoint Eventhandler updating fields for a document in a document library

I got a task where documents can be published to a document library. Published documents should get properties attached that are stored in a seperate custom list with a custom content type.

The documents derive all from that custom list content type.

So I wrote an eventhandler for an Updated and Added event to load all the fields from the custom list entry and if the document has also that fields, wrote the value.

At the end i just put in properties.ListItem.Update() and it updates the item. That was my development machine.

In production there came an error across: The document has to be checked out to update its properties. Ah, ok.

Because its only metadata in my mind and the user cannot control if the file gets checked out and i don't want to increment the version number i searched for an alternative method. I could'nt turn off "versioning" and "checkout requirement".

Long term, short answer: just call listItem.SystemUpdate(false).

This bypasses the "normal" checkout and list settings and just updates the item and does not increment the version number (if you use the second ctor with the bool. bool incrementListItemVersionNumber). BE SURE TO KNOW WHAT YOU DO :)

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.systemupdate.aspx

Keine Kommentare: