.Net - using FileIOPermission with mask in file name
Posted
by Max Gontar
on Stack Overflow
See other posts from Stack Overflow
or by Max Gontar
Published on 2010-03-31T05:39:36Z
Indexed on
2010/03/31
5:43 UTC
Read the original article
Hit count: 501
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?
© Stack Overflow or respective owner