Three Cases of List Manipulations in Recent Real Life Cases

February 12 2010 3 comments

Case 1: AllowDeletion

There might be a case where you have custom document libraries in your SharePoint-solution bound to a customer specific custom content type. It might be confusing for the customer to have the default libraries, which come when the Office SharePoint Server Publishing feature has been activated.

“Some user will at some point inevitably put his/her documents to Documents-library, which we don’t want to be using instead of the document library designed especially for us”, the customer might rightfully state. Well, how can you respond if you have not been clever enough to be prepared in the process of development for such a need? You can’t just give advice to delete unnecessary libraries because some – and in this case the Documents-library – lists are not permitted to be deleted.

Permissions and Management

Permissions and Management

One solution might be to crawl the site structure and set SPList’s AllowDeletion property to true and then recycle the list once and for all. How to do it? Here’s one solution:

private static void ListAllowDeletion(SPWeb web, string listName,
bool allowdeletion, bool recycle, bool recursive)
        var list = web.Lists[listName];
        list.AllowDeletion = allowdeletion;
        Console.WriteLine("AllowDeletion property set to {0}:
        List Title {1}, Web Url {2} "
, allowdeletion.ToString().ToLower(),
        listName, web.Url);
        if (recycle && list.AllowDeletion)
            Console.WriteLine("Recycled: List Title {0}, Web Url {1}",
            listName, web.Url);
    catch (ArgumentException)
        Console.WriteLine("List {0} not found in web {1}", listName,

    if (!recursive) return;

    foreach (SPWeb sub in web.Webs)
        if (sub.Exists)
            ListAllowDeletion(sub, listName, allowdeletion, recycle,

The ListAllowDeletion-method could be part of a console application – as it in this case is – and the command argument driven use of the solution could be to give the following arguments to the execution:

  • site’s url, from which you instantiate SPSite object
  • web’s url, from which you instantiate SPWeb object under the site
  • list name, from which you instantiate SPList object under the web
  • recursive, boolean to determine if the operation concerns only the given web (false) or do you want the operation to concern the whole structure under the given web (true)
  • recycle, boolean to determine if the list is to be removed from the web to recycle bin, if the list permits deletion
  • allow deletion, boolean to set to the list’s AllowDeletion-property (true/false)

This might be a bit awkward because there is always the possibility to programmatically bind your custom content type to the oob lists as you wish but that’s another story and not part of this scenario.

What about when the sites are created, the unwanted lists appear in the new sites and there is again no way to delete them via the user interface. This case is solved by creating web-scoped feature, which sets the wanted list’s AllowDeletion-property and – if wanted – also recycles the wanted list. You could accomplish this by creating a common feature receiver which does all that (the above C# sample contains all the essentials, just drop the recursive-option and the Console.WriteLines) and is given directions via the feature’s properties. You could use the same feature receiver to set some other list’s AllowDeletion-property false if you want to prohibit the list deletion option from the user interface.

<?xml version="1.0" encoding="utf-8"?>
    Title="Documents-library Recycle Feature"
    Description="This Feature Recycles Documents-library"
    ReceiverAssembly="MyAssembly, Version=, Culture=neutral,

    <Property Key="CommaSeparatedListTitles" Value="Documents" />
    <Property Key="AllowDeletion" Value="true" />
    <Property Key="Recycle" Value="true" />

Case 2: SPListItem Recycle vs. Delete

If you ever need to do list item manipulation to large scale lists, you might want to consider Recyle instead of Delete. This is somewhat confusing and not necessarily comes to mind as in the user interface you don’t have those two options, only “Delete Item”, which moves the item to recycle bin. So if your scenario is to iterate large amount of list items, do something to the items based on a condition and finally remove some items from the list, I would suggest to recycle the items because delete via API loses the item permanently from the database and recycle doesn’t. I’ve learnt this the hard way by having to restore content database from a backup and use the content deployment API to get the lost items back online.

Case 3: Custom List and Datasheet View

Do you have a custom User-typed site column, which is referred in a custom content type that is bound to custom document library? If so, have you ever tried to edit the document library in Datasheet View and wondered why you’re not able to pick users to the custom user-field? That might be because your site column doesn’t have the following attributes:


UserSelectionMode: 0 is for people only, 1 is for people and groups
UserSelectionScope: 0 is for all users

If those attributes are updated to your site column, you will be able to pick users in Datasheet View in your custom user field.

Popularity: 1% [?]

3 comments to “Three Cases of List Manipulations in Recent Real Life Cases”

  1. Thnx for this post, just got here using Google. I never thought about this actually, glad you made a post about this. Keep it up! :)

  2. Juha Pitkänen says:

    Don’t remove any of the libraries (Documents, Images, Pages) Office SharePoint Server Publishing -feature creates by using the suggested method or any other method. PublishingWeb-object stores ID’s (guids) of the libraries and presents them through DocumentslistId-, PagesListId- and ImagesListId-properties. Those properties are internal, so you cannot (easily) alter them. Lack of those three libraries in publishing web can and will cause unexpected behavior when API tries in some cases load information which isn’t no longer present.

  3. I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100% positive. Any suggestions or advice would be greatly appreciated. Thanks

Leave a Reply