Tuesday, July 26, 2011

What is SharePoint?

SharePoint is a magic framework and content management system. Why magic? It is difficult to explain, you should start work with SharePoint to understand it. Imagine the situation: you implement solution during 2-3 month. Everything works nice, all testers said: "There is no bugs". But several hours before deployment on test servers or even production event receivers stop working. Why? I think even Microsoft doesn't know why event receivers some times doesn't work. You will start rewrite logic, but it is too late. So some builds with this process - and you become a sharepoint apologizer :)
Only after some time of experience you will know what can we use in sharepoint and what is jungle and unusable.
Sometimes you should spend hours to change a simple label on the page.
Also there are some problems with testers. And many problems with new testers. They really don't know what is sharepoint and what belongs to your solution. They start report sharepoint bugs, they start sharepoint testing, skip major bugs in your solution. It was a problem on my first project. In some time testers have learned sharepoint functionality, but to speed up this process I recommend to pass some sharepoint trainings.
And there are more and more questions, bugs etc. But some customers like sharepoint and in some years of experience you probably like it too )). I recommend to pay attention to javascript libraries, implement lightweight solution as ajax based. It is a good point to implement your own sharepoint framework and reuse it. This framework can include:
1. Data layer, working with data.
2. Working with ajax requests.
3. Working with permissions and etc.

Tuesday, June 14, 2011

Delete items from SharePoint list and document libraries

Some days ago I had a problem to delete all items from standard SharePoint list. There are the following possible ways to do it:
  1. Delete list at all and create it once again. This option is very fast but we need to create the list again with all fields, views etc. It is a rounite operation and could take much time. Also it can be item event receiver for delete action that makes some changes. The delete list operation without delete all items may cause some problems depending on the logic in the receiver.
  2. Select all list items and delete it.
Option 2 was more preferable for me. I had a Classes list with timetable for English courses. The list had about 11.000 items and sometimes I had to delete them for my purposes. Also this list had one item event receiver for delete action - to delete classes from classes workspaces. So I've started to implement this solution as console application. The code was very simple - create SPSite, SPWeb objects, find list and select all items using empty SPQuery. After implementation I've started to test my solution. The overall performance was about 50-90 items per minute. I was very surprised but in a short time I've found the problem. The item event receiver execution was too long. In this case the only one way is to delete items from list in threads. I've added a required parameter - number of threads. Each of them delete its portion of list items. After implemenation and testing the overall performance was 2000-3000 items per minute using 15 threads. So the whole delete operation is taking about 3-4 minutes now. This is a good result for me. The following code split all list items to batches for an every thread: