FileIOPermissionAccess.Append : FileIOPermissionAccess : Security C# Source Code


Custom Search

C# Source Code » Security » FileIOPermissionAccess »

 

FileIOPermissionAccess.Append








    
 

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

class Program {
    static void Main(string[] args) {
        CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"C:\audit.txt");
        permission.Deny();
        AuditClass.Save("some data to audit");
        CodeAccessPermission.RevertDeny();
    }
}

class AuditClass {
    public static void Save(string value) {
        try {
            FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"C:\audit.txt");
            permission.Assert();
            FileStream stream = new FileStream(@"C:\audit.txt",FileMode.Append, FileAccess.Write);
            CodeAccessPermission.RevertAssert();
            Console.WriteLine("Data written to audit file");
        } catch {
            Console.WriteLine("Failed to write data to audit file");
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Security
» FileIOPermissionAccess