Creating a new file with specific access rule : File Access Rule « File Directory Stream « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Security;
using System.Security.AccessControl;
using System.Security.Policy;
using System.Security.Permissions;
using System.Security.Principal;
using System.Text;

public class MainClass
{
    public static void Main()
    {
        string fileName = "c:\\test.txt";
        FileSecurity acl = new FileSecurity();
        acl.AddAccessRule(new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name,
            FileSystemRights.CreateFiles | FileSystemRights.Modify | FileSystemRights.Delete,
            AccessControlType.Allow));
        using (FileStream file = File.Open(fileName, FileMode.OpenOrCreate))
        {
            
        }
    }
}








15.11.File Access Rule
15.11.1.Set File access rule
15.11.2.Add file access rule
15.11.3.Creating a new file with specific access rule