Read-only directories in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vrsantos
    New Member
    • Feb 2008
    • 1

    Read-only directories in C#

    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.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Read only for who?
    Unless you set the readonly attribute with "attrib", it only makes a special rule based on the windows user.
    For that, you should probably get the ACL for it and look through those.

    Comment

    Working...