Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. folder access writes

folder access writes

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chandler83
    wrote on last edited by
    #1

    in my application i can drag and drop folders and files....... problem is: if i drag and drop a folder which has no access writes... how can i differentiate tht folder from a normal folder. Directory.Exists is giving me true for both the case... I am getting this System.UnauthorizedAccessException. is thr any property which differentiates between these folders.:confused:

    N 1 Reply Last reply
    0
    • C chandler83

      in my application i can drag and drop folders and files....... problem is: if i drag and drop a folder which has no access writes... how can i differentiate tht folder from a normal folder. Directory.Exists is giving me true for both the case... I am getting this System.UnauthorizedAccessException. is thr any property which differentiates between these folders.:confused:

      N Offline
      N Offline
      Niiiissssshhhhhuuuuu
      wrote on last edited by
      #2

      Use public DirectorySecurity GetAccessControl () for eg; using System; using System.IO; using System.Security.AccessControl; namespace FileSystemExample { class DirectoryExample { public static void Main() { try { string DirectoryName = "TestDirectory"; Console.WriteLine("Adding access control entry for " + DirectoryName); // Add the access control entry to the directory. AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Removing access control entry from " + DirectoryName); // Remove the access control entry from the directory. RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow); Console.WriteLine("Done."); } catch (Exception e) { Console.WriteLine(e); } Console.ReadLine(); } // Adds an ACL entry on the specified directory for the specified account. public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { // Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName); // Get a DirectorySecurity object that represents the // current security settings. DirectorySecurity dSecurity = dInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings. dInfo.SetAccessControl(dSecurity); } // Removes an ACL entry on the specified directory for the specified account. public static void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType) { // Create a new DirectoryInfo object. DirectoryInfo dInfo = new DirectoryInfo(FileName); // Get a DirectorySecurity object that represents the // current security settings. DirectorySecurit

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups