ファイル名にマスクを使用して、一連のファイルに FileIOPermission を適用したいと思います。フォルダー C:\TMP 内のすべての txt ファイル:
[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();
}
}
}
これにより、ArgumentException "Illegal characters in path." がスローされます。
なにが問題ですか?とにかく達成することは可能ですか?