Check If File Exist Or Not Using VB.NET

Checking of file is important while making programs which are supposed to do file handling.
You can check whether file exist or not in visual basic.net by importing System.IO namespace.




Code :

For Declaration :
Import System.IO

On Button Click, Form Load Etc ;

If file.exist(filename) then
desired_action 
else
desired action 
End If


Let us take an example , if we wants to check that any specific file [ let file name be 'abc.txt' ] exist or not. If it exist , show a message that file exist else display message that file not exist.

Complete Code :




Image For Reference :






In this example , we are checking file named as abc.txt . You can change the file name & its extension as per as your requirement. Note that the file will be checked in the directory [Folder] where this file check application exist. If you want to check file in any folder , add complete path & file name with extension as given below:

C:\User\ND\Example\YourFile.jpg

When user will click the button , it will perform the file check operation and deliver output [In this example , it will display message ] according to the condition fulfilled above.