OpenFileDialog Codes

Example : How to browse files from User’s desired Folder.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        OpenFileDialog1.InitialDirectory = "E:\New Folder\New Folder1"
        OpenFileDialog1.RestoreDirectory = True
        
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                PictureBox1.ImageLocation = OpenFileDialog1.FileName 
        End If
End Sub

NB : If User's folder path is incorrect/not available, then System Default Folder works automatically 
     works.
Example : How to browse files form System Default Folder.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then  'File's Browsing Code
         PictureBox1.ImageLocation = OpenFileDialog1.FileName  'File's Attaching Code in Picture Box
     End If
End Sub
Example : How to browse files from System Default Folder with File’s path detail.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
           TextBox2.Text = OpenFileDialog1.FileName      'Show full Path of browsing image.
           PictureBox1.ImageLocation = TextBox2.Text
     End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
 If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  TextBox2.Text = Path.GetFileName(OpenFileDialog1.FileName)'Show only image file name,not full path.
  PictureBox1.ImageLocation = TextBox2.Text
 End If
End Sub
Example : How to browse files from User’s desired Folder with File’s path detail.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     OpenFileDialog1.InitialDirectory = "E:\New Folder\New Folder1"
     OpenFileDialog1.RestoreDirectory = True

     If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
           TextBox2.Text = OpenFileDialog1.FileName      'File's Path Detail code.
           PictureBox1.ImageLocation = TextBox2.Text
     End If
End Sub
---------------  OR  ---------------

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        OpenFileDialog1.Title = "Please Select Photo"
        OpenFileDialog1.InitialDirectory = "F:"
        OpenFileDialog1.ShowDialog()
        Picture1.ImageLocation = OpenFileDialog1.FileName.ToString
        Picture1.Visible = True
End Sub

SaveFileDialog Codes

 9,717 total views,  15 views today

Categories: VB .Net

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.