tags:

views:

126

answers:

2

This seems odd to me. I'm using FolderBrowserDialog to select a folder which will be the destination of a bunch of files. Whenever create and select a folder within the dialog, the resulting folder always seems to be read-only when I view the folder in Explorer afterwards.

I've checked the documentation for the FolderBrowserDialog.ShowNewFolderButton property but I see nothing about the access settings for the folder, nor have I been able to see a way of changing the access setting to the folder.

You'd think this would be simple. Anyone have any ideas?

+1  A: 

The folders created in the dialog box inherit the parent folder permissions. If you need the parent read only and the child not read only, then you'll need to use a filewatcher to look for new directories and change the read only attributes on it, when it sees a new folder.

gjutras
Inheriting the parent folder permissions seems to be correct. I'm not sure about the filewatcher right now, but the answer solved the basic problem.But how does one change the read only attribute on a folder in .NET?
Valentein
A: 

I actually found that DirectorySecurity.SetAccessControl method met my needs:

            DirectoryInfo dirInfo = new DirectoryInfo(this.destinationText.Text);
            DirectorySecurity dSecurity = dirInfo.GetAccessControl();
            dSecurity.AddAccessRule(
                         new FileSystemAccessRule("SYSTEM",
                                                  FileSystemRights.FullControl,
                                                  AccessControlType.Allow));
            dirInfo.SetAccessControl(dSecurity);
Valentein