.Net - using FileIOPermission with mask in file name
- by Max Gontar
Hello!
I would like to apply FileIOPermission on set of files using mask in file name, ex. on all txt files in folder C:\TMP:
[type: FileIOPermission(SecurityAction.PermitOnly, Read = @"C:\TMP\*.txt")]
class SomeClass
{
static void testPermissions()
{
Console.WriteLine("allowed action");
File.OpenRead(@"C:\TMP\1.txt"); // <--- here goes exception
Console.WriteLine("denied action");
try
{
File.Create(@"C:\TMP\2.txt");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.ReadKey();
}
}
}
This throws ArgumentException "Illegal characters in path."
What is wrong? Is it possible to achieve anyway?