How to use OpenFileDialog1 with TextFieldParser?

aman_VB

Member
Joined
Apr 27, 2010
Messages
23
Programming Experience
1-3
It seems like in order to use "TextFieldParser " you need to include the path of the file to be parsed. Is it possible to use OpenFileDialog1 and then choose a file? I keep getting error messages.
-------------------------------

Public Class Form1

Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click

Dim openFileDialog1 As New OpenFileDialog()
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.InitialDirectory = "C:\Users\Documents\")
--------------------------
 
I think this code should work for you
VB.NET:
        Dim openFileDialog1 As New OpenFileDialog

        If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Using myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(openFileDialog1.FileName)

            End Using
        Else
            'The user closed the dialog without choosing a file
        End If

Hope this helps

Satal :D
 
Back
Top