Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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 { }
}
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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