+92 332 4229 857 99ProjectIdeas@Gmail.com

OpenFileDialog (Vb.net)


OpenFileDialog

OpenFileDialog is used to ask the user to open a file.

openFile function returns the path of the file which is selected to open.

ofd is an object of OpenFileDialog class which is used to call different functions contained in the OpenFileDialog class.

ofd.Filter function is used to get the file formats to be displayed in the OpenFileDialog box.

ofd.Multiselect function used to set the value indicating whether OpenFileDialog will allow multiple files to be selected or not.

 ofd.FileName returns the name of the file which is selected.

.ShowDialog() function shows the OpenFileDialog box.

Code:

1.     Public Function openFile() As String
2.     Dim name As String = String.Empty
3.     Dim ofd As New OpenFileDialog
4.     ofd.Filter = "|*.xls"
5.     ofd.Multiselect = False
6.     With ofd
7.     If .ShowDialog = Windows.Forms.DialogResult.OK Then
8.     name = ofd.FileName
9.     End If
10.  End With
11.  Return name
12.  End Function

0 comments: