我想为特定用户设置一个只读文件夹,他应该无法编辑或删除它,我尝试了下面的代码但它不起作用,我需要对其进行哪些更改
try
{
string folderPath = textBox1.Text;
string username = comboBox1.SelectedItem.ToString();
DirectorySecurity ds = Directory.GetAccessControl(folderPath);
FileSystemAccessRule fsa =
new FileSystemAccessRule(username,
FileSystemRights.ReadAndExecute,
AccessControlType.Allow);
ds.AddAccessRule(fsa);
Directory.SetAccessControl(folderPath, ds);
MessageBox.Show("ReadOnly");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}