Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WinForm
how can we give permisson in c# so that no one can delete file.
 
i am using this code but it does not work .any one please help me where i am doing wrong. it work for all like full control/read/write/modify. but it does not work for delete
 
  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 20 Jan '12 - 19:53
Edited 21 Jan '12 - 3:07
ambarishtv10.4K

Comments
pradeep rasara - 21 Jan '12 - 3:18
i wnt to make it in window application

3 solutions

Use File.SetAccessControl[^] on the file.
  Permalink  
Comments
pradeep rasara - 21 Jan '12 - 3:49
But i have tried this it does not work.
pradeep rasara - 21 Jan '12 - 4:25
actually it works for full control,read, write.......but does not work for delete.
Kim Togo - 21 Jan '12 - 4:36
Under FileSystemRights Enumeration link, There is a FileSystemRights.Delete that "Specifies the right to delete a folder or file."
pradeep rasara - 21 Jan '12 - 4:39
ya i have try this but does not work,it work for all except delete. but i want to do with delete
Kim Togo - 21 Jan '12 - 6:04
You can try to experiment with file access control in Windows Explorer, and have another user login that do not have the same access. When you found a combination that works. Use File.GetAccessControl to readout what types of access list is need.
pradeep rasara - 23 Jan '12 - 7:11
but it also do not work through Window explorer. I tried my best.
  Permalink  
Comments
NeptuneHACK! - 21 Jan '12 - 6:22
this is the best solution i guess. thank you all any ways :)
use Message Boxes and
 
1) you can use modal popup extender,you need to use this in userControl.asmx file and then call it in your page.
 
a). Select The User Control by Right click on solution explorer
b). Call the extender on UserControls
c). use its directive on the page
d). call it by using Label.
 
2)
You can use MessageBox
 
Page.ClientScript.RegisterStartupScript(this.gettype(),"ok","javascript:alert('Don't Delete');",true);
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 273
1 Sergey Alexandrovich Kryukov 179
2 Maciej Los 136
3 Richard MacCutchan 125
4 Tadit Dash 100
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,917
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,125


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 21 Jan 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid