OpenFileDialog

G

Guest

I can't get the following msdn code below to actually open the .txt file i
select
It seems
Return DlgOpenFile.OpenFile()
or
Return New FileStream(Path, System.IO.FileMode.Open, _
System.IO.FileAccess.ReadWrite)
don't actually do anything.

Please help as I need this working for my prototype tomorrow.



Private Function OpenFile() As FileStream

' Displays an OpenFileDialog and shows the read/only files.

Dim DlgOpenFile As New OpenFileDialog()
DlgOpenFile.ShowReadOnly = True
Dim Fs As FileStream

If DlgOpenFile.ShowDialog() = DialogResult.OK Then

' If ReadOnlyChecked is true, uses the OpenFile method to
' open the file with read/only access.

If DlgOpenFile.ReadOnlyChecked = True Then

Return DlgOpenFile.OpenFile()

' Otherwise, opens the file with read/write access.

Else

Dim Path As String = DlgOpenFile.FileName
Return New FileStream(Path, System.IO.FileMode.Open, _
System.IO.FileAccess.ReadWrite)

End If

End If

End Function
 
H

Herfried K. Wagner [MVP]

marcmc said:
I can't get the following msdn code below to actually open the .txt file i
select
It seems
Return DlgOpenFile.OpenFile()
or
Return New FileStream(Path, System.IO.FileMode.Open, _
System.IO.FileAccess.ReadWrite)
don't actually do anything.

You'll find some samples for reading data from text files or binary files
here:

Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top