VB.Net - File / Folder Exists

VB.Net - How To Check If File / Directory Exists Using Visual Basic.Net

VB.Net Folder Exists


In This VB.Net Tutorial  We Will See How To Verify If File Or A Folder Exists From A Path String Using Visual Basic.Net Programming Language.


Project Source Code:

Imports System.IO

Public Class File_Folder_Exist

' File Exists
    Private Sub ButtonFile_Click(sender As Object, e As EventArgs) Handles ButtonFile.Click

        Dim filePath As String
        filePath = TextBox_File_Path.Text

        If File.Exists(filePath) Then

            MessageBox.Show("File Exist")

        Else

            MessageBox.Show("File Not Exist")

        End If

    End Sub

' Folder Exists
    Private Sub ButtonFolder_Click(sender As Object, e As EventArgs) Handles ButtonFolder.Click

        Dim folderPath As String
        folderPath = TextBoxFolderPath.Text

        If Directory.Exists(folderPath) Then

            MessageBox.Show("Folder Exist")

        Else

            MessageBox.Show("Folder Not Exist")

        End If

    End Sub
End Class



Share this

Related Posts

Previous
Next Post »