title: Protect single file!
body: <p>I'm trying to protect a folder and the files inside it.<br>
  I'm able to protect the folder itself, so that if somebody clicks on it he will get a message:
  "You don't currently have permission to access this folder!"</p>
  
  <p>But I can still access files in that folder. For example, if somebody knows the name of a file inside the folder he can type D:\ProtectedFolder\pdffile.pdf and he can open the file!</p>
  
  <p>So, my question is:</p>
  
  <p>Can I protect single files inside the folder?</p>
  
  <p>This is the function that I use for folder lock:</p>
  
  <pre><code>   Public Function Lock(ByVal folder As
   String, ByVal user As String)
          Dim FilePath As String = folder
           Dim fs As FileSystemSecurity = File.GetAccessControl(FilePath)
           fs.AddAccessRule(New FileSystemAccessRule(user,
   FileSystemRights.ListDirectory,
   AccessControlType.Deny))
           fs.AddAccessRule(New FileSystemAccessRule(user,
   FileSystemRights.FullControl,
   AccessControlType.Deny))
           File.SetAccessControl(FilePath, fs)
         Return 0
  
      End Function
  </code></pre>
  
  <p>Thanks!</p>