I have one issue which is in fact solved, but I totally do not understand why it behaves like this.
So I have a network share and I would like simply to verify if I have access to create new files and directories in that share. I have used two approaches to solve that, but in both I get different result. My test case is that I can't create files and directories on that share:
Trying to create a new Directory — not a nice way
try
{
var testPath = Path.Combine(path, testDirectory)
Directory.CreateDirectory(testPath)
}
catch
{
// No access
}
This is a way which I do not like at all, but it works... I have an exception here, so it says correctly that I do not have the permission on specific path.
Using FileIOPermission — nicer way
try
{
var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, path)
var appendPermission = new FileIOPermission(FileIOPermissionAccess.Append, path)
writePermission.Demand()
appendPermission.Demand()
}
catch
{
// No access
}
With that approach I do not have any exception so it says to me that I have the permission to create new files — which is actually not true.
Anyone knows what is wrong with the second approach?