Append a File Using VB.NET

This article explains how to append a file in VB.NET.
  • 5251

Append a File

The AppendText method creates a StreamWriter object that appends UTF-8 encoded text to an existing text file. There will be times when you won't want to erase all the text from your file. You'll only want to add text to what you currently have. In which case you need to Append.

Imports System.Text

Imports System.IO

Module Module1

    Sub Main()

        Dim fileName As String = "C:\Temp\Text.txt"

        Dim fi As New IO.FileInfo(fileName)

        Using sw As StreamWriter = fi.AppendText()

            sw.WriteLine("--------- Append Text Start ----------")

            sw.WriteLine("New author started")

            sw.WriteLine("a book on Files Programming ")

            sw.WriteLine("using C#")

            sw.WriteLine("--------- Append Text End ----------")

        End Using

        ' Read all text

        Dim readText As String = File.ReadAllText(fileName)


    End Sub

End Module





More Articles

© 2020 DotNetHeaven. All rights reserved.