Hi,
Here is a code snip. It uses the OpenFileDialog control. Note, I am using
it to read data in "chunks" from a file and then to send those "chunks" out
the serial port. However, you can do equivalent things (such as simply
displaying the file), rather than sending it.
OpenFileDialog1.ShowDialog()
Dim Filename As String = OpenFileDialog1.FileName
If Filename <"" Then
Dim fs As New System.IO.FileStream(Filename, IO.FileMode.Open,
IO.FileAccess.Read)
'declaring a FileStream to open the file with access mode of reading
logReader = New System.IO.BinaryReader(fs)
'creating a new StreamReader and passing the filestream object fs as
argument
logReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)
Dim FileLength = logReader.BaseStream.Length
Dim BytesRemaining As Integer = FileLength
With SerialPort
Do Until BytesRemaining < SerialPort.WriteBufferSize
Try
Dim buffer(.WriteBufferSize - 1) As Byte
buffer = logReader.ReadBytes(.WriteBufferSize)
..Write(buffer, 0, .WriteBufferSize)
BytesRemaining -= .WriteBufferSize
Catch ex As Exception
Exit Do
End Try
Loop
'etc
For this reason, I use a BinaryReader. You might choose to use a TextReader
instead. If you examine the Filename result from the OpenFileDialog, you
can see how paths are handled for Storage Cards.
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See
www.hardandsoftware.net for details and contact information.