Declarative Permission demo : File Permission « File Directory Stream « C# / CSharp Tutorial






using System;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Text;


    class Program
    {
        [FileIOPermission(SecurityAction.Demand, AllLocalFiles=FileIOPermissionAccess.Write)]
        static void Main(string[] args)
        {
            FileStream fs = new FileStream("myfile.txt", FileMode.Create);
            fs.WriteByte(65);
            fs.Close();
        }
    }








15.12.File Permission
15.12.1.Requesting minimum permissions
15.12.2.Requesting optional permissions
15.12.3.Requesting a permission set
15.12.4.Refusing permissions
15.12.5.Demanding permissions
15.12.6.Permission sets
15.12.7.Declarative Permission demo