- podcast
- research
- search
- security
- technology
- video
- AIM
- Alfresco
- Collaboration
- ECM
- ESX
- Hyper-V
- IE8
- Internet Explorer
- Iomega
- Linux
- MIX08
- Microsoft
- NAS
- Nokia
- REV
- S60
- SaaS
- Sharepoint
- Silverlight
- Sony Ericsson
- VMware
- Windows Live
- YouTube
- advertising
- backup
- beta test
- blogs
- convergence
- display
- enterprise
- humans
- instant messaging
- multimedia
- networking
- open source
- phishing
Working with ListAdding and ListDeleting Events
SharePoint 2010 now provides events for the Lists, an expected and welcome update. There are a number of events that are added to the list event, but this article will take a look at two of them as shown in blue in the chart, namely ListAdding, ListDeleting. The subsequent article will show and discuss ListAdded and ListDeleted events, shown in grey.
What these events bring is power to fulfill complex business requirements. For example consider a scenario where you want to delay the deletion of specific lists and only allow immediate list deletion if deletion is initiated by certain user, or you may want to stop the addition of a new List based on type of the list.
To sum up, it not only opens doors for managing complex requirements it also provides room to be more innovative when approaching business scenarios. In this example, you will see how to limit the creation of lists based on List Template ID, i.e. on the basis of the type of list, plus you will also see how the list deletion works.
The example uses Visual Studio 2010 Beta 2, along with SharePoint Server 2010 Beta. Once you have the development environment setup you can proceed as follows.
1. Launch the Visual Studio 2010, and create a new project. Expand Visual C# (you can also choose Visual Basic, but this example will use Visual C#). Select SharePoint from the Installed Template and then select 2010; from the right-hand pane select Event Recevier. In the Name field type ListEvents and in the Solution Name type in Tip-12-ListEvents.
NOTE: Make sure that from the top drop down .NET Framework 3.5 is selected. Also make sure that your project is targeted against x64 not x86, you can change it once project is created, not from New Project dialog.
Finally click OK to create the project.
2. Select Deploy as a farm Solution and click next.
3. Select List Events and then check events as shown below.
4. The following figure shows the newly created Project and its files.
5. The stubs of the events that you selected earlier are already created; what is required is to start putting in code for desired behavior.
6. For the first scenario, the ItemAdding event will be used, and as this event fires up before the List is actually created, the List object cannot be used, as it will be null at this moment. Instead properties object in the method parameter (of type SPListEventProperties), has TemplateId property which contains the Template ID of the List, that is about to be created.
Also note that it also contains a property called ListTitle which gives title of the list. Now, to stop creation of any new Document Library, check the TemplateId such that its not equal to 101 which refers to Document Library. Following code fragment shows this.
7. For the second scenario, you will write code inside ListDeleting method, the check is made to inquire if the list has items inside it, in which case deletion is cancelled. See the following code.
8. Click F5 inside the Visual Studio to Build and Deploy the solution. Visual Studio will take care of deploying the ListEvents handlers.
9. On the SharePoint Site, click on Site Actions, View All Site Content.
10. Click Create.
11. Click on the Document Library, and type Sample in the text box, and then click Create button.
You will see an error message from ListAdding event handler and as a result Document Library will not be created.
12. Now for the second scenario, you need to have a list (any SharePoint list) with some items in it, for this you may want to create a custom list and then add some elements to it (not shown here), and then finally try to delete it. You will see the following error from the ListDeleting Event and List will not be deleted.
To sum up, the new Lists events provide great benefit to developers to fulfill the requirements both form IT admins sites and from business users. In the subsequent article the ListAdded and ListDeleted events will be discussed along with new option of showing users custom error page while cancelling the events.
Most Popular Stories
- 1 Solve Item-Level Permission Performance Problems in SharePoint
- 2 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 3 Leveraging SharePoint as a Document Management System
- 4 Developing SharePoint Solutions in Visual Studio Using WSPBuilder
- 5 Use jQuery to Kill Spell Checker in SharePoint Lists
- 1 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 2 Leveraging SharePoint as a Document Management System
- 3 Solve Item-Level Permission Performance Problems in SharePoint
- 4 Provide SharePoint Single Sign-On with Active Directory Federation Services
- 5 SharePoint 2010 Makes the Link to LINQ
- 6 Developing SharePoint Solutions in Visual Studio Using WSPBuilder
- 7 Use JavaScript to Hide SharePoint's Quick Launch Bar

While Java helps in fulfilling the promise of "write once, use anywhere", there are practical concerns developers need to address in developing their code, whether it's porting from another language, working in the best IDE or optimizing for today's multi-core computing environments. This eBook will help you in understanding these issues and how you can get the most out of your Java code.