Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:53pm
Edited 21-Jan-12 3:07am
ambarishtv10.5K
v4
Comments
pradeep rasara at 21-Jan-12 3:18am
   
i wnt to make it in window application
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use File.SetAccessControl[^] on the file.
  Permalink  
Comments
pradeep rasara at 21-Jan-12 3:49am
   
But i have tried this it does not work.
pradeep rasara at 21-Jan-12 4:25am
   
actually it works for full control,read, write.......but does not work for delete.
Kim Togo at 21-Jan-12 4:36am
   
Under FileSystemRights Enumeration link,
There is a FileSystemRights.Delete that "Specifies the right to delete a folder or file."
pradeep rasara at 21-Jan-12 4:39am
   
ya i have try this but does not work,it work for all except delete. but i want to do with delete
Kim Togo at 21-Jan-12 6:04am
   
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 at 23-Jan-12 7:11am
   
but it also do not work through Window explorer. I tried my best.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
NeptuneHACK! at 21-Jan-12 6:22am
   
this is the best solution i guess. thank you all any ways :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
0 OriginalGriff 328
1 Gihan Liyanage 292
2 Sergey Alexandrovich Kryukov 275
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web03 | 2.8.140826.1 | Last Updated 21 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100