How to run code when creating a SharePoint list?

I am aware of event receivers in the list of added items. However, I did not find a way to tan the code when creating the list.

What I'm trying to do is associate the workflow with the list when creating the list (by the user through the user interface).

Any ideas?

thanks.

+4
source share
4 answers

There are several routes you can take ...

You can write your own list definition in which you define a workflow relationship. This way, all lists created based on your list definition will contain your default workflow.

Or ... depending on your workflow ... write an EventReceiver that will be attached to all lists of the type to which you want to attach your workflow (some function can be easily reached) and your event receiver will bind the workflow when the first item is added.

or you can associate a workflow with the type of content used in the list (your own type of content that you attach to your own list definition or default for SharePoint content)

I do not know the rest is your decision, so I can offer you the best solution.

What I (almost) always do is write my own list definition. Thus, I can avoid such problems, both now and in the future.

+6
source

With SharePoint 2010, you can now connect to the list creation event by overriding the ListAdded event in the SPListEventReceiver class.

+3
source

I usually use an extra view page, which is set to the default view. When the user creates the list, he will be sent to the viewing page containing the installation in the code. Then, the ive method is called on the browse page, which changes the default view, deletes the setup view, and modifies any node navigation that points to the setup view.

+1
source

There is probably no perfect answer to this question, because there is no event receiver with an added list (if the memory suits me).

I don’t know if this is so, but if you really needed to register the event with the addition (or updated, deleted, etc.) to any new list, I believe that you can register these events on the site (SPWeb), and they will be launched in any newly created lists.

+1
source

All Articles