Directory.CreateDirectory access to path is denied?

Murhaf Sousli picture Murhaf Sousli · Feb 25, 2012 · Viewed 35.8k times · Source

enter image description here

I have server-client application, it's a file manager
my problem is when I go inside a folder which requires access control like system folders, it becomes to read-only, but I need to move/delete or create new folder, how can I get the permission to do that?

here's how I create a new folder at the server side

public void NewFolder(string path)
    {
        try
        {
            string name = @"\New Folder";
            string current = name;
            int i = 0;
            while (Directory.Exists(path + current))
            {
                i++;
                current = String.Format("{0} {1}", name, i);
            }
            Directory.CreateDirectory(path + current);
            Explore(path); //this line is to refresh the items in the client side after creating the new folder
        }
        catch (Exception e)
        {
            sendInfo(e.Message, "error");
        }
    }

Answer

user1227804 picture user1227804 · Feb 25, 2012

If you want to remove directory read-only attribute use this: http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/cb75ea00-f9c1-41e5-ac8e-296c302827a4

If you want to access system folders you can run your program as local administrator.