danucalovj

Set file permissions in VB.NET

Jul 25th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.63 KB | None | 0 0
  1. Imports System.Security.AccessControl
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  6.         Dim FilePath As String = "Test.txt"
  7.         Dim UserAccount As String = "Everyone"
  8.         Dim FileInfo As IO.FileInfo = New IO.FileInfo(FilePath)
  9.         Dim FileAcl As New FileSecurity
  10.         FileAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.FullControl, AccessControlType.Allow))
  11.         'FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
  12.         FileInfo.SetAccessControl(FileAcl)
  13.     End Sub
  14. End Class
Advertisement
Add Comment
Please, Sign In to add comment