We Help You To Renovate Your Blogger Blog With Awesomeness!

Showing posts with label File and Folder Permission. Show all posts
Showing posts with label File and Folder Permission. Show all posts

Saturday, September 20, 2014

  • How to set read write permission to directory in C#.NET

    While working with files and directory we need read write permission on files and folders, this can be done by manually giving access permission to directory as well as programmatically.


    private static void SetPermissions(string dirPath)
    {
        DirectoryInfo info = new DirectoryInfo(dirPath);
        WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent();
        DirectorySecurity ds = info.GetAccessControl();
        ds.AddAccessRule(new FileSystemAccessRule(self.Name,
        FileSystemRights.FullControl,
        InheritanceFlags.ObjectInherit |
        InheritanceFlags.ContainerInherit,
        PropagationFlags.None,
        AccessControlType.Allow));
        info.SetAccessControl(ds);
    }

     read-only on access on file
    FileInfo myFile = new FileInfo(files.FullName);
    myFile.IsReadOnly = false;
      File with Read Write permission

    FileStream F = new FileStream("test.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite);

  • Copyright @ 2013 Code Snippets.