Write to a text file while is it open and visible

592 Views Asked by At

I'm sure this is really simple, but has had me stumped for a while!

I need to show the user a text file, with lines being written to it as my program executes. Stuff like "Working on this file - Successful!". Another forum thread has helped me to allow the text file to be accessed by multiple processes, but now when I open the text file using Process.Start, it doesn't show the lines that are being written using the StreamWriter. Any help very much appreciated.

Code:

Dim ExportLog As String = "C:\ExportLog.txt"

    If System.IO.File.Exists(ExportLog) Then
        System.IO.File.Delete(ExportLog)
    End If

    Using writeStream = System.IO.File.Open(ExportLog, 
           FileMode.OpenOrCreate, FileAccess.ReadWrite,      
           FileShare.ReadWrite), Write As New StreamWriter(writeStream)

        Write.WriteLine("Starting")
    End Using

    Dim MyLog As Process = Process.Start(ExportLog)
0

There are 0 best solutions below