4

I have the requirement for multiple document libraries. Each document library will contain the same types of document, images, office documents; however, when items are added to the library, a custom event receiver will trigger, and perform very different actions on the items placed within the library.

Given the scenario above, would it be benefical for me to create a number of custom document libraries based from the document library template, each with its own ID, so that I can target specific event receivers to libraries of a particular type?

3

A list item adding event receiver can be associated with either a content type, list, site or a site collection. So your requirement suggests multiple document libraries and you will then associate the various event receivers with them. In fact I can't think of an alternative way of achieving this ([edit] that makes sense given what you have told us).

2
  • 1
    not unless you count workflows :-) Jun 1 '11 at 12:11
  • I wasn't counting workflows; question asked for an event receiver. Good point, though.
    – SPDoctor
    Jun 1 '11 at 14:39
1

Right, I guess you're trying to tie your event handlers to list types 'cos you're using CAML, and the examples in the documentation all seem to add to document libraries via the ListTemplateId.

However, you can add via a ListUrl - thus targetting specific lists. There is an example here. From that link:

<Receivers ListTemplateId="104">

Change this line to

<Receivers ListUrl="Lists/TestAnnouncements">

So you could have a number of normal document libraries, and tie your event handlers to those individual libraries.

Alternatively, if you're talking about treating the files differently according to their mimetype, you could just use a switch statement within your event receiver.

Finally, if you're using different Content Types for the different types of file, you could tie your event receivers to the Content Type.

Either of these last two options would let you use 1 library. Whether you want to or not is a design question.

2
  • Andy the issue with tying to the URL is that in the future the client will want the ability to create more document libraries, and will expect that the event receivers tied to them work in the same manner. I cannot know the URLs they may create in advance Jun 1 '11 at 14:08
  • Ah, right! They you're right - define your own Library Templates is probably the safest way.
    – Andy Burns
    Jun 1 '11 at 14:34

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.