0

How can I allow users to create folders but not delete folders in SharePoint 2007?

2

Create a event reciever using the following code and then attach the event reciever to your document libraries.

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

    if (!user.IsSiteAdmin)
    {
        return false;
    }
    else
    {
        //admins can delete folder
        return true;
    }
}

public override void ItemDeleting(SPItemEventProperties properties)
{
    try
    {
        if (properties.AfterProperties["ContentType"].ToString() == "Folder")
        {
            using (SPWeb web = properties.OpenWeb())
            {
                if (!CanDeleteFolder(web))
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "Cannot add folder at this location. Please select a sub folder";
                    properties.Status = SPEventReceiverStatus.CancelWithError;
                }
            }
        }
    }
    catch { }
}
| improve this answer | |
1

Or create a custom permission level that does not allow the delete option and apply that permission level to the library for the desired users. They'll be able to add/edit items but not delete. An event receiver seems like overkill for a simple permissions change.

| improve this answer | |
0

Could use a custom event receiver to trap OnDeleting to see if the current item being deleted is a folder, and Cancel if so, presenting an error message whilst doing so.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.