Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me.
this code i used to deny delete operation on a file . but it is not working for administrator Account.
its working with limited user account(for example guest account/compuetr account which doesnt have full control) .
plz help me.

i want to deny delete operation for administrator account and limited user account when some one delete file .
C#
private void button1_Click(object sender, EventArgs e)
        {
            string fileName = @"E:\kkk.txt";
 
            WindowsIdentity ident = WindowsIdentity.GetCurrent();
            WindowsPrincipal user = new WindowsPrincipal(ident);
 
            AddFileSecurity(fileName, user.Identity.Name,
                      FileSystemRights.Delete, AccessControlType.Deny);
        }
 
  public static void AddFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {
           
            FileSecurity fSecurity = File.GetAccessControl(fileName);
 
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));
   
          File.SetAccessControl(fileName, fSecurity);
 
        }
Posted
Updated 25-Jun-12 20:31pm
v4
Comments
pradeep rasara 26-Jun-12 3:15am    
please someone help me. give any idea about this.....

1 solution

set this attribute to the file
C#
File.SetAttributes(fileName, FileAttributes.ReadOnly);

i think this will help you
 
Share this answer
 
v2
Comments
pradeep rasara 26-Jun-12 4:55am    
its not working.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900