StreamReader error

  • Thread starter Thread starter ext237
  • Start date Start date
E

ext237

Hello.

I am trying to open a filestream using the following code:

Dim myStreamReader As StreamReader = New StreamReader( _

New FileStream("H:\files\file.txt", FileMode.Open), _

System.Text.Encoding.Unicode)


I receive the following error:

"An unhandled exception of type 'System.UnauthorizedAccessException'
occurred in mscorlib.dll

Additional information: Access to the path "H:\files\file.txt" is
denied."

Any suggestions? The code is in a VB class that I'm calling from a
different project.

Thanks.
 
You do not need to create a new FileStream object in the instantiation of
the StreamReader. It will accept a text file directly.

Try this:

Dim myStreamReader As New StreamReader("H:\files\file.txt")

Of course, you need to have permissions to the drive/file.
 
Back
Top