Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When a user is creating a new document by selecting "new" on a document library it should be possible via an event trigger to call some custom code that will update the document attributes. As far as I know this can't be done through the SPList events as ItemAdding will not be triggered when the document is created, but when the document is saved later on. Will the Content Type events be the way to implement the requested functionality?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I take it you are talking about SharePoint 2007 (please tag post accordingly:-) Depending on what you want to achieve, hook into the ItemAdding, ItemAdded, ItemUpdating or ItemUpdated event.

All will be called as the provisioning process includes updating meta data for the document. If you have enabled checkin/checkout i think the update events will fire twice, but Im not 100% on that as its been a while since I ran into that problem.

For the same reason remember to disable event firing in a try/finally:

If you choose update events, remember that the logic will also fire when you later update the item. To distinguish look in the BeforeProperties or AfterProperties for evidence of what the source of the event is (there is some vti_something fields that will give evidence what caused the event to fire).

Im not on my box right now so I cant test the above, but anyone feel free to add on the above and correct me if im wrong :-)

share|improve this answer
    
Hi Anders. The question should be version agnostic, unless the event model in 2010 has changed. I just tested when the event trigger ItemAdding is fired, and as far as I can tell it happens when the user saves the document to the list, and for my purpose that is way to late. I'll need a trigger that fires when the document is "new'ed" –  Kasper Bo Larsen Jun 7 '10 at 6:27
    
ok maybe you could describe in a bit more details what you want to achieve then? With "new'ed" i presume you mean when (one of) the "new" buttons are pressed? This could get very tricky to achieve with any kind of consistency as there are various ways in both browser/UI, explorer and client (eg Word) to do this. Without having digged into this, a way of getting any consistency here could be to use either an httpModule or a httpHandler (bound to specific extensions) where the first probably is the best suggestion. –  Anders Rask Jun 7 '10 at 6:42
    
.. or as an alternative if we are talking Office documents, consider VSTO –  Anders Rask Jun 7 '10 at 7:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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