This application is really basic but is pretty neat to make. This application will be able to browse through files on your computer and upon opening a file will display an output “File Exists” or “File Not Found.” At first the code may seem foreign, but I will add comments that help explain what the code is doing.

Setting Up

If you have not done so already, set up an empty web site. Open visual studio and click on File > New > Project. Expand Other Languages > Visual Basic, select Windows Forms Application, name the file Browse a File and click OK.

Step One

You will see a blank form, let’s add a text box and button to make this application function. Open the toolbox panel, grab a TextBox item and place it on the form. Click on the text box and look in the properties window. Change it’s name to txtFileDirectory, as this text box will represent the file name directory. Now from the toolbox place a Button item on the form. This button will be the button that initiates the browsing for a file. In it’s properties, change the name to btnBrowse and change the text to Browse.

file browser 1

Step Two

Double click on the Browse button to open the visual basic class of the form. By double clicking on the button, we create an event handler called btnBrowse_Click that handles code each time the button is pressed. All of the methods used in this code is from a class called ‘OpenFileDialog’ that prompts the user to open a file. I also took the liberty to add comments above the lines of code that explain what is happening line by line.

Output

Run the application and click the Browse button. A file browser will open up in the local C drive and if you notice in the extension file next to the file name, we allow extensions of data files or all files. Open a file that exists and a message box will pop up saying “File Exists:” with the file directory next to it, and if you click OK the file directory will appear on the text box in the form.

file browser 2

file browser 3

This is a basic example of what can be done when working with file directories. Files can be uploaded and downloaded, so there are quite a bit of possibilities available. First get familiar with this tutorial and then go into the more advanced programming.

Download Source Files