Results 1 to 5 of 5

Thread: [RESOLVED] winform OpenFileDialog

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2007
    Posts
    694

    Resolved [RESOLVED] winform OpenFileDialog

    Hello,
    The following code shows how to use the openFileDialog to read the contents of a .csv file into a textbox.

    Question:
    After selecting the file iin the dialog, how do I actually open the file?
    remember that I would like to open the .csv file and NOT read it into the textbox.

    Dim ts as StreamReader
    openFileDialog1.CheckFileExists = true
    openFileDialog1.CheckPathExists = true
    openFileDialog1.DefaultExt = "csv"

    openFileDialog1.Filter = "Text files (*.csv)|*.csv|" + "All files|*.*"
    openFileDialog1.Multiselect = false
    openFileDialog1.FilterIndex = 2
    openFileDialog1.ValidateNames = true

    if (openFileDialog1.ShowDialog() = DialogResult.OK)

    ts = StreamReader(openFileDialog1.OpenFile())

    txtSQL.Text = ts.ReadToEnd()
    end if

    Thanks

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: winform OpenFileDialog

    Just use the Process.Start method

    Process.start(openFileDialog1.FileName)

    This open the file in default editor

    More info : http://msdn.microsoft.com/en-us/libr...50(VS.71).aspx

    Hope this helps

    Dana

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [RESOLVED] winform OpenFileDialog

    The thread has be marked as resolved ?

    Have got your answer ?

  4. #4
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [RESOLVED] winform OpenFileDialog

    vb Code:
    1. Me.OpenFileDialog1.Filter = "All Microsoft CSV Files|*.csv"
    2.  Me.OpenFileDialog1.Title = "Select the CSV Document to Open"
    3.  Me.OpenFileDialog1.FileName = ""
    4.  If OpenFileDialog1.ShowDialog = DialogResult.OK Then
    5.     If IO.Path.GetExtension(OpenFileDialog1.FileName) = ".CSV" Then
    6.         Me.OpenFileDialog1.Dispose()
    7.         Me.SendToBack()
    8.         System.Diagnostics.Process.Start(OpenFileDialog1.FileName)
    9.     End If
    10.  End If
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2007
    Posts
    694

    Re: [RESOLVED] winform OpenFileDialog

    Yes, I have the answer.
    Many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width