Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Cracking down on Folders in SharePoint

with 14 comments

Much has been said for and against using folders in lists and document libraries. Leaving these discussions aside, what if you want to disable folders entirely in a list or library? This post describes how you can remove the New + Folder menu from lists and libraries, but unfortunately this does not stop folders being created using other techniques.

For example, in a document library with the New + Folder menu removed, you can still create a folder by:

  1. Use Actions + Open in Windows Explorer in the Document, Library, right-click and select New + Folder.
  2. In Microsoft Word, choose File + Save, navigate to the SharePoint document library, right-click and choose New + Folder.

So, I’ve been on a quest to suppress these capabilities, but so far with no success. I’ve tried:

  1. Using code and the class libraries to remove the hidden “Folder” content type. I can remove the content type, but folders can still be created.
  2. Set the EnableFolderCreation property for the SPList object to false (this just does the same as removing the New + Folder menu command).
  3. And other things…but to no success.

In many organisations imposing standards on how document libraries are used is important, and if a decision has been made not to use folders then this should be applied no matter how the user attempts to create the folder.

Any other ideas? 

Advertisements

Written by Nick Grattan

December 2, 2007 at 6:50 pm

14 Responses

Subscribe to comments with RSS.

  1. how about a demerit for every folder creation offense? 🙂 I’ve been trying to figure out the same thing for myself, no luck yet though other than verbally stating that sub folders are not to be used.

    Henry

    December 7, 2007 at 5:24 am

  2. Best answer I’ve had to this problem! Nick

    nickgrattan

    December 17, 2007 at 2:49 pm

  3. With regards to this matter, i am researching a way to give users access to create documents but not create folders. Any workarounds around this?

    Nicholas

    January 18, 2008 at 2:27 am

  4. Firstly you need to implement the suggestions above – removing the Add Folder item from the menu.

    Secondly you need a developer to attach an event receiver to the document library in question.

    The ItemAdding event is triggered whenever someone tries to add an item to the list in question (by whatever means), and a folder is just a special content type within a list. ItemAdding is triggered BEFORE the item is added, and the operation can easily be cancelled ([C#] properties.Cancel = true;) before the folder is ever added. That ought to make it totally impossible to add a folder to the list.

    SamV

    January 30, 2008 at 12:46 pm

  5. When I create a Document Library programmatically on MOSS 2007, is there anyway to disable the “Folder creation” for that Doc.Lib programmatically?
    It can be done, via Advance Settings and then disable.

    Is there anyway that it can be done “programmatically” ?

    mInNaL

    February 12, 2008 at 11:32 pm

  6. FYI: If you want to access the content type from the ItemAdding method, use the AfterProperties:

    if (((string)properties.AfterProperties[“ContentType”]) == “Folder”)
    {
    // put code here
    }

    gbelzile

    February 20, 2008 at 3:53 pm

  7. would removing the new folder content type from your site collection remove the ability to create folders in doc libs.

    erugalatha

    May 2, 2008 at 10:56 am

  8. Thanks for the suggestion. Don’t think you can – the “Folder” content type is “sealed” and cannot be deleted. Nick.

    nickgrattan

    May 2, 2008 at 11:25 am

  9. In my case, I had a folder in which I didn’t wanna let anothers to be create, only a custom content type I had made. I used this:

    //Create a list with the available contentTypes
    List cTypes = new List();
    cTypes.Add(atividadeCType);

    //Set the content types available to the folder
    properties.ListItem.Folder.UniqueContentTypeOrder = cTypes;
    properties.ListItem.Folder.Update();

    Properties comes in the itemAdded event and atividadeCtype is my custom content type.

    Anselmo

    July 15, 2008 at 5:34 pm

  10. Has anyone found a solution for this problem?

    Tony

    August 18, 2009 at 11:37 am

  11. Has anyone found the solution that is easy to foloow by a non developer?

    amirbutt

    September 15, 2011 at 6:11 am

  12. Hi I have the same requirement and came across this blog http://sharepointserved.blogspot.com/2011/05/to-prevent-users-from-creating-folders.html
    However I am not sure if it works. Has anyone tried this out and is successful in implementing it?

    EN

    February 9, 2012 at 4:27 am

    • Yes, you can try this, I’ve implemented this code successfully.

      Prasath C

      February 17, 2012 at 1:34 pm

      • Me too. It works as written. However, I want to get fancy and allow folders only for those in a super-privileged group (ECM) while disallowing for all others. I can’t make that seem to work. Using the following to detect membership…

        //only enforce this rule if the user is NOT in the ECM group
        bool isInECM = false;
        SPGroupCollection groups = properties.OpenWeb().SiteGroups;
        SPGroup ecmGroup = groups[“ECM Group”];
        isInECM = ecmGroup.ExplicitlyContainsCurrentUser;

        …I then try to use this (lots of different ways attempted) to cancel the event only for those not in the group. This works fine for the New Folder link in the ribbon but is ignored for the WIndows Explorer route. I guess I just don’t understand how the latter works.

        B. Altner

        August 25, 2012 at 5:29 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: