SharePoint's security model can be very granular, but it lacks a feature. The ability to control who can add/edit/delete folders. This can be very useful when an organization needs to control it's folder structure within a document library. The only way that I have found to do this is to create an event handler on the library.<!--more-->

There are a couple ways to attach an event handler to a library, but I have chosen to attach it using SharePoint's API through a feature receiver...

<strong>Feature Receiver</strong>
<pre><code>public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    using (SPSite site = new SPSite("http://www.mysite.com"))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.Lists["Shared Documents"];

            SPEventReceiverDefinition defDeleting = list.EventReceivers.Add();

            defDeleting.Assembly=
"AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f4da34656c37ec3";
            defDeleting.Class = "Namespace.ClassName";
            defDeleting.Name = "ItemDeleting Event";
            defDeleting.Type = SPEventReceiverType.ItemDeleting;
            defDeleting.SequenceNumber = 1000;
            defDeleting.Synchronization = SPEventReceiverSynchronization.Synchronous;
            defDeleting.Update();
        }
    }
}</code></pre>
And then we have the event handler.

<strong>Event Handler</strong>
<pre><code>public override void ItemDeleting(SPItemEventProperties properties)
{
    try
    {
        SPListItem item = properties.ListItem;

        if (item.FileSystemObjectType == SPFileSystemObjectType.Folder)
        {
            using (SPWeb web = properties.OpenWeb())
            {
                if (!isOwner(web))
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "You are not authorized to delete folders.";
                    properties.Status = SPEventReceiverStatus.CancelWithError;
                }
            }
        }
    }
    catch { }
}

private bool isOwner(SPWeb web)
{
    //Check to see if the user is in the owners group
    SPUser user = web.CurrentUser;

    if (!user.IsSiteAdmin)
    {
        return false;
    }
    else
    {
        //Only Admins can modify folder
        return true;
    }
}
</code></pre>
The example above only shows how to control the Delete function, but adding the Create and Modify functionality is very simple. When anyone other than an Owner of this site collection tries to delete a folder in the Shared Documents library, they will receive an error stating "You are not authorized to delete folders." like the one you see below...

<a href="http://blogs.eGroup-us.com/wp-content/uploads/2011/01/SPError1.jpg"><img class="size-full wp-image-3280 alignnone" src="http://blogs.eGroup-us.com/wp-content/uploads/2011/01/SPError1.jpg" alt="SharePoint Delete Folder Error" width="580" height="258" /></a>