Hello. I'm trying to build a simple FTP uploader. How can I make it so the user can select a file to upload? See, what I want is to have a button (which I do) that a user can click, and it shows the OpenFileDialog (which I have), but then when they select a file, I want its path to be shown in a text box. How can I do that? Screenshot: http://i49.tinypic.com/oi9idg.jpg
A:
use the OpenFileDialog
http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog.aspx
Raj More
2010-02-01 18:34:19
A:
You want to get the OpenFileDialog's property Filename property. See OpenFileDialog's class members here on MSDN.
Hope this helps, Best regards, Tom.
tommieb75
2010-02-01 18:37:22
+3
A:
Try the following code
Dim dialog As New OpenFileDialog()
If DialogResult.OK = dialog.ShowDialog Then
TextBox1.Text = dialog.FileName
End If
JaredPar
2010-02-01 18:37:38
Argh. Reverse order of comparison in the `If`? **In VB**?!
Konrad Rudolph
2010-02-01 18:41:29
@Konrad, it's an almost unbreakable habit from my C days.
JaredPar
2010-02-01 18:43:15
@Jared: I’m lucky then that I made the transition in the other direction. ;-) I just hope there aren’t *too* may BASIC idioms in my C++ code.
Konrad Rudolph
2010-02-01 19:09:53
+1
A:
One way is to convert the filename to a FileInfo which contains all sorts of information about the file including the path. This opens the dialog and displays the path of the selected file.
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim fi As New System.IO.FileInfo(OpenFileDialog1.FileName)
TextBox1.Text = fi.DirectoryName
End If
djbaldwin
2010-02-01 18:42:29