VB.Net - Create File And Directory

VB.Net - How To Create File And Folder Using Visual Basic.Net

VB.Net Create Directory


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


Project Source Code:

Imports System.IO

Public Class Create_File_Directory

' create file if not exist
    Private Sub ButtonCreateFile_Click(sender As Object, e As EventArgs) Handles ButtonCreateFile.Click

        Dim filePath As String
        filePath = TextBoxFilePath.Text

        If File.Exists(filePath) Then

            MessageBox.Show("File Already Exists")

        Else
            File.Create(filePath)

        End If


    End Sub

' create folder if not exist
    Private Sub ButtonCreateFolder_Click(sender As Object, e As EventArgs) Handles ButtonCreateFolder.Click

        Dim folderPath As String
        folderPath = TextBoxFolder.Text

        If Directory.Exists(folderPath) Then

            MessageBox.Show("Folder Already Exists")

        Else

            Directory.CreateDirectory(folderPath)

        End If

    End Sub
End Class



Share this

Related Posts

Previous
Next Post »