Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:40:45+00:00 2026-06-11T12:40:45+00:00

I am removing removing permissions from a folder to given users i want to

  • 0

I am removing removing permissions from a folder to given users i want to be able to remove the user from the folder security tab list

excerpt code

myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule(User, FileSystemRights.Write | FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
     PropagationFlags.None, AccessControlType.Allow));

                myDirectoryInfo.SetAccessControl(myDirectorySecurity);

i want to remove the user after permission is remove..

picture http://i93.photobucket.com/albums/l66/reavenm/Capture_zps51403cae.png

i tried to add that to my code here

DataSet dataSet = new DataSet(); 
string sql = "SELECT key, fdate, user, perm, sfolder FROM  permuser WHERE        fdate=CURDATE()";

MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand cmdSel = new MySqlCommand(sql, connection);
new MySqlDataAdapter(cmdSel).Fill(dataSet, "permuser");


foreach (DataRow row in dataSet.Tables["permuser"].Rows)
    {
         string fuser = row["user"].ToString();
         string pathtxt = row["sfolder"].ToString();

        DirectoryInfo myDirectoryInfo = new DirectoryInfo(pathtxt);
        DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
        string User = System.Environment.UserDomainName + "\\" + fuser;


                myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule(User, FileSystemRights.Write | FileSystemRights.Read, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
     PropagationFlags.None, AccessControlType.Allow));

                myDirectoryInfo.SetAccessControl(myDirectorySecurity);
                   //it should go here
    }

connection.Close();
connection.Dispose();
}


catch (MySqlException ex)
{
Console.WriteLine(ex.Message);
Environment.Exit(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:40:46+00:00Added an answer on June 11, 2026 at 12:40 pm

    We use the following to remove users/groups from folders they no longer have access to.

    var accountToRemove = "Some account";
    var security = Directory.GetAccessControl(path);
    var rules = security.GetAccessRules(true, true, typeof(NTAccount));
    
    foreach (FileSystemAccessRule rule in rules)
    {
        if (rule.IdentityReference.Value == accountToRemove) 
            security.RemoveAccessRuleSpecific(rule);
    
    }
    

    Replace your foreach loop with the following

    foreach (DataRow row in dataSet.Tables["permuser"].Rows)
    {
         string fuser = row["user"].ToString();
         string pathtxt = row["sfolder"].ToString();
    
        DirectoryInfo myDirectoryInfo = new DirectoryInfo(pathtxt);
        DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
        string User = System.Environment.UserDomainName + "\\" + fuser;
    
        var rules = myDirectorySecurity.GetAccessRules(true, true, typeof(NTAccount));
        foreach( var rule in rules)
        {
            if (rule.IdentityReference.Value == User) 
                security.RemoveAccessRuleSpecific(rule);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems removing index.php from codeigniter-2. I remember using the same code
Removing annotations from my map view in the following way: if ([[self.mapView annotations] count]
For removing trailing part is I use the code str.substring(0,str.length -2) Is there a
After removing hash from URL using window.location.hash='' page getting reloaded in firefox. EDIT Example:
In IE8 when dynamically removing TR elements from a table inside a DIV with
I'm having trouble removing a gem from my system. When i ask gem where
Error: Database table users for model User was not found. I'm expriencing the error
we've created a custom webpart to display announcements from all lists a user has
When removing files from a Git repository I accidentally also removed a file that
I have a code that creates file(s) in user-specified directory. User can point to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.