VB.Net Create And Write In Text File

How To Create And Write In A TXT File Using Visual Basic.Net

create file in vb.net



In this VB.Net Tutorial we will see How To Create A Text File From A Specific Path And Write Into It Text From A TextBox In Visual Basic.Net Programming Language And Visual Studio IDE .




Project Source Code:

Imports System.IO

Public Class CreatFileAndWrite


    Private Sub Btn_CreateAndWrite_Click(sender As Object, e As EventArgs) Handles Btn_CreateAndWrite.Click

        Dim filePath As String
        filePath = "C:\\Users\\omar\\Desktop\\haha\\folder1\\myTextFile.txt"

        If File.Exists(filePath) Then

            MessageBox.Show("File Already Exists")

        Else

            File.Create(filePath).Dispose()
            MessageBox.Show("File Created")

            Dim sw As StreamWriter
            sw = New StreamWriter(filePath)
            sw.WriteLine(RichTextBox1.Text)
            sw.Close()

        End If

    End Sub
End Class
                                       

////// OUTPUT : 

write in text file using vb.net



Share this

Related Posts

Previous
Next Post »