My goal in this part of my application is to warn the user if they select a directory/folder for use as a report depot that is read only, not accessible to them.
Based on several solutions from this web site and others, I have tried the following
DirectoryInfo di = new DirectoryInfo(sConnectionFolder);
if ((di.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
// WARN THE USER
My problem is, when testing with a read-only folder, the di.Attributes property's value is merely 'Directory', and does not contain the flag/component for read-only.
from the debugger:
di.Attributes = Directory
So my warning code is never executed.
What I have tried:
Other attempts:
if (di.Attributes.HasFlag(FileAttributes.ReadOnly))
// and steering clear of DirectoryInfo, just using FileInfo:
FileAttributes file_attr = (new FileInfo(sConnectionFolder)).Attributes;
// and lastly, using File class to get the attributes:
FileAttributes fa = File.GetAttributes(sConnectionFolder);
// all with the same result: Directory for the attribute value
// Why is the read-only flag not present?