Home All Groups Group Topic Archive Search About
Author
29 Jun 2005 4:41 PM
marcmc
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

Author
29 Jun 2005 4:47 PM
Herfried K. Wagner [MVP]
"marcmc" <mar***@discussions.microsoft.com> schrieb:
>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>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>