Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27186

VS 2010 [RESOLVED] Reading and displaying text contents of an open txt file using rtb

$
0
0
I have a code that records all the user interaction with an application on a text file.

Code:

    Public Shared fs As New FileStream(Application.LocalUserAppDataPath & "\mcb.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
    Public Shared m_streamWriter As New StreamWriter(fs)

    Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ' Write to the file using StreamWriter class
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End)
        m_streamWriter.Write(" File Write Operation Starts : ")
        m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
        m_streamWriter.WriteLine(" ===================================== " + ControlChars.Lf)
        m_streamWriter.Flush()
    End Sub

Now I want to display the contents of the text file on a richtextbox, but I'm getting an error. This is my code for displaying

Code:

Me.rtbTrack.LoadFile(Application.LocalUserAppDataPath & "\mcb.txt", RichTextBoxStreamType.PlainText)
The error I'm getting is "The process cannot access the file 'C:\Users\Tum\AppData\Local\Powerware_System\Powerware System\1.0.0.0\mcb.txt' because it is being used by another process."

Any suggesion of getting my way out of it? Is it possible to read an open file, open in the same application? Please lead me...

Thank you..

Viewing all articles
Browse latest Browse all 27186

Trending Articles