Create directory with full control to all users

Posted on 2011-10-18
Last Modified: 2013-12-16
I need to create a directory with full control to all users. Can anyone show me the code to do that?

Question by:Thomasian
    LVL 10

    Expert Comment

    by:Chad Smith

    string path = @"C:\test";
        DirectorySecurity ds = Directory.GetAccessControl(path);
        ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
        Directory.SetAccessControl(path, ds);

    Open in new window

    LVL 22

    Author Comment

    When I checked the permission of the folder created, it has "Special Permissions" checked instead of "Full Control".

    Any ideas?
    LVL 17

    Accepted Solution

    Hello, try this:
    System.Security.AccessControl.DirectorySecurity dirSecurity = new System.Security.AccessControl.DirectorySecurity();
        new System.Security.AccessControl.FileSystemAccessRule("Everyone",
        System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit,
    // Create the new folder with the custom ACL.
    System.IO.Directory.CreateDirectory(@"C:\Temp\MyNewDir", dirSecurity);

    Open in new window

    LVL 22

    Author Closing Comment

    Perfect! Thanks!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now