Check File IO Permission : Security « Security « VB.Net






Check File IO Permission

Imports System.Security.Principal
Imports System.Security.Permissions
Imports System.IO


public class MainClass
   Shared Sub Main()
        Dim oFp As FileIOPermission = New _
        FileIOPermission(FileIOPermissionAccess.Write, "d:\test.txt")
        oFp.Assert()
        Try
            Dim objWriter As New IO.StreamWriter(File.Open("d:\test.txt", IO.FileMode.Open))
            objWriter.WriteLine("Hi there!")
            objWriter.Flush()
            objWriter.Close()
            objWriter = Nothing
        Catch objA As System.Exception
            Console.WriteLine(objA.Message)
        End Try

   End Sub
End Class



           
       








Related examples in the same category

1.Registry Permissions Demo
2.Environment Permissions DemoEnvironment Permissions Demo