Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 6-13 extracted from chapter Security


Listing 6-12<     > Listing 6-14


This listing can be compiled with the command line:
csc.exe /target:exe Example_6_13.cs
Errors: 0 Warnings: 0


Example_6_13.cs
using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;
class Program {
   static void Main() {
      // Fill the DACL.
      FileSecurity dacl = new FileSecurity();
      // Fill the DACL with an ACE.
      FileSystemAccessRule ace = new FileSystemAccessRule(
         WindowsIdentity.GetCurrent().Name,
         FileSystemRights.AppendData | FileSystemRights.ReadData,   
         AccessControlType.Allow);
      dacl.AddAccessRule( ace );
      // Create a new file which has this DACL.
      System.IO.FileStream fileStream = new System.IO.FileStream( 
            @"file.bin" FileMode.Create , FileSystemRights.Write , 
            FileShare.None, 4096 FileOptions.None, dacl );
      fileStream.Write( new byte[] { 012}, 0);
      fileStream.Close();
   }
}	
Copyright Patrick Smacchia 2006 2007