Sunday, 29 January 2012

vb.net code for open file dialog box ?

How to use open file dialog box in vb.net?
This tutorial you can learn how to open file dialog box in vb.net, 
Step1:
Open Microsoft visual studio2010
Step2:
Open file new à windows form application à Rename it as open file dialog box
Step3:
Drag and drop button1, from toolbox
Step4:
Write or copy the below code
Code:
Public Class Form1

    Private SubButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click
        Dim ofd As New OpenFileDialog
        'ofd.ShowDialog()
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim filename As String
            filename = ofd.FileName
            MessageBox.Show(filename)
        End If

    End Sub
End Class

Output:


message box will show which file you selected