brinda lakhani

brinda lakhani

  • NA
  • 13
  • 5.8k

How to set permission on folder in c#?

Feb 17 2015 11:55 PM
Hello,
I am developing a window application in c#.net. I want to make my folder lock. Folder can't be delete, open, copy and paste. Only I want to insert the images in folder by pragmatically and retrieve those images.
This is my code. Using this, I am only able to insert the images and also can't delete the folder but when I am going to move this folder in some other folder that can be move and after moving the folder all rights are removed.
How to do this ? Please help me out.
Code :-
private void Permissionbtn_Click_1(object sender, EventArgs e)
{
DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + comboBox1.SelectedItem.ToString();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.ListDirectory, AccessControlType.Deny));
}

Answers (1)