Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:\My Documents"
OpenFileDialog1.ShowDialog()
End Sub
Code (VB.NET)
Imports System
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing
Public Class MainClass
Shared Sub Main()
Dim myFileDialog As OpenFileDialog = New OpenFileDialog()
With myFileDialog
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.InitialDirectory = "C:\My Documents"
.Title = "Open File"
.CheckFileExists = False
End With
If myFileDialog.ShowDialog() = DialogResult.OK Then
Console.WriteLine(myFileDialog.FileName)
End If
myFileDialog = Nothing
End Sub
End Class