Example

Please note the use of an absolute path, as opposed to a relative path, in the following example.

using System;
using System.IO;
using System.Security;
using System.Security.Permissions;

[assembly:FileIOPermissionAttribute(
     SecurityAction.RequestMinimum,
     All=@"C:\Temp\BCL")]

namespace Samples
{
  public class FileIOPermissionAttributeSample
  {
    public static void Main()
    {
      using(FileStream output =
                         File.Create(@"c:\Temp\BCL\file.txt"))
      {
        Console.WriteLine("Name: {0}", output.Name);
      }
    }
  }
}
The output is
Name: c:\Temp\BCL\file.txt

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.