How can I make the "view file .." button in VB.net?

I am trying to create a simple FTP downloader. How can I do this so that the user can select the file to upload? Look, I want to have a button (which I do) that the user can click and it shows OpenFileDialog (which I have), but then when they select the file, I want its path to appear in the text box . How can i do this?

+3
source share
4 answers

Try using the following code

Dim dialog As New OpenFileDialog()
If DialogResult.OK = dialog.ShowDialog Then
  TextBox1.Text = dialog.FileName
End If
+4
source

One way is to convert the file name to FileInfo, which contains all kinds of file information, including the path. A dialog box opens and the path to the selected file is displayed.

If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    Dim fi As New System.IO.FileInfo(OpenFileDialog1.FileName)
    TextBox1.Text = fi.DirectoryName
End If
+1

Filename OpenFileDialog. . OpenFileDialog , MSDN.

,

0

Add OpenFileDialog and add this code

If YourOpenFileDialogName.ShowDialog = YourOpenFileDialogName.OK Then 
 textBox1.Text = YourOpenFileDialogName.FileName
End If
0
source

Source: https://habr.com/ru/post/1730901/


All Articles