Hi.
How can I verify if a given directory is read-only in C# ? I tried it using this approach:
DirectoryInfo d = new DirectoryInfo(@ "C:\Test");
if (d.Attributes == FileAttributes. ReadOnly)
// do something
But it doesn't works, even if I set manually (in Windows) the directory to read-only. The attribute is always 'Directory'.
One way of doing that is trying to create a subdirectory (with d.CreateSubdire ctory) wrapped by try/catch statements, and catching an eventual UnauthorizedAcc essException, but I don't think it's a good practice.
Can anyone help me?
Thanks in advance.
How can I verify if a given directory is read-only in C# ? I tried it using this approach:
DirectoryInfo d = new DirectoryInfo(@ "C:\Test");
if (d.Attributes == FileAttributes. ReadOnly)
// do something
But it doesn't works, even if I set manually (in Windows) the directory to read-only. The attribute is always 'Directory'.
One way of doing that is trying to create a subdirectory (with d.CreateSubdire ctory) wrapped by try/catch statements, and catching an eventual UnauthorizedAcc essException, but I don't think it's a good practice.
Can anyone help me?
Thanks in advance.
Comment