Currently I’m busy in creating huge amounts of folders and I want to have the best performance doing so. So.. I know about the ProcessBatchData method on the SPWeb object that is designed to do ‘batch’ stuff in a very optimized way. Only problem was that I never created folders by using this method.
I thought “hey.. a folder is just a list item with it’s content type set to Folder right?” So by defining the ContentType, the folders were created!! Yeah!! But… SharePoint now was treating this ListItem as a File so it uses the “Name” column instead of the “Title” column to display the Title. So every folder looked like this :
![folders_notitle[1] folders_notitle[1]](/Blogs/Robin/Lists/Photos/folders_notitle.png)
To fix this I tried the adding following fields :
- BaseName, generating error “Bad parameter passed to Web Server Extensions. Check the information you entered and try again”
- Name, generating error “One or more field types are not installed properly. Go to the list settings page to delete these fields”
in combination with the “urn:schemas-microsoft-com:office:office” schema and without but all the same result.
Here is the xml snippet which I use if you are interested ;)
string methodFormat = "<Method ID=\"{0}\">" +
"<SetList>{1}</SetList>" +
"<SetVar Name=\"ID\">New</SetVar>" +
"<SetVar Name=\"Cmd\">Save</SetVar>" +
"<SetVar Name=\"urn:schemas-microsoft-com:office:office#Title\">{2}</SetVar>" +
"<SetVar Name=\"urn:schemas-microsoft-com:office:office#ContentType\">Folder</SetVar>" +
"</Method>";
I found the Save Method (RPC) page on MSDN which explains a lot of this mysterious CAML and tried a lot of different things but didn’t get any further. Maybe that was a good thing as well since it states that “This method is deprecated and may not be supported in future releases. Instead, use the following Web service method: UpdateListItems Web service method.” So I went there and to my suprise (and delight) the method also accepts a ‘batch’ string. So by using the following snippet I managed to create all the folders I wanted :
string methodFormatListItem = "<Method ID='{0}' Cmd='New'> " +
"<Field Name='FSObjType'>1</Field>" +
"<Field Name='BaseName'>{1}</Field>" +
"<Field Name='ID'>New</Field></Method>";
Only thing that keeps me worried is ‘ how bad is the performance when using the webservice instead of the ProcessBatchData? ’ By doing a test that creates 100 folders 9 times in a row I came up with the following results table (each number is the time measured in milliseconds) :
| ProcessBatchData |
UpdateListItems |
| 1916 |
3236 |
| 874 |
963 |
| 1058 |
846 |
| 1310 |
967 |
| 682 |
1042 |
| 824 |
1128 |
| 674 |
1012 |
| 721 |
1424 |
| 648 |
1077 |
And in a graph it looks like this:
So actually only the first hit is the most expensive one but after the first one, it becomes quite reasonable in my opinion. Of course the ProcessBatchData is the better performing one but the webservice wasn’t that bad as I thought it would be.
Useful references:
Technorati Tags:
SharePoint