In one of my projects I am using a path in the System.Environment.SpecialFolder.CommonApplicationData
folder (in my case C:\ProgramData) to store configuration and registration data. However I ran into problems. I check if I can access the files by using the routine
Dim isok As Boolean = True
Try
Dim ftry As New IO.FileStream(frmMain.APPDATA & "\regid.bin", FileMode.Open)
ftry.Close()
Catch ex As Exception
isok = False
End Try
APPDATA is the path to my config folder and I check if the file actually exists before that as well (it does). On one machine this routine returns false for me. The exception says no file access. If I rewrite this routine:
Dim isok As Boolean = True
Try
Dim contents() as Byte = IO.File.ReadAllBytes(frmMain.APPDATA & "\regid.bin")
Catch ex As Exception
isok = False
End Try
It returns true, so the IO routines obviously can access the file.
Can someone explain to me what the difference between the two methods are? Shouldn't file access be determined by the application's privileges? Is there a better way to determine if I have read/write access to the file?