Text File Issue

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
Hi,

I have a program that will read the file line automatically each of the time and get the all the result based on the text files.

So, i try to add new line in the current text file, but it failed, it does not allow me to save. Why?

textfilexs4.jpg


**My program will keep on looping and retrieve the info based on above text files

Thanks your help.
 
I assume the file is not open by another application?

Can you post the code so that we can see it?

this is my coding in the TIMER
VB.NET:
 Dim fs As Stream = File.Open(lblFileName.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Dim reader As New StreamReader(fs, True)
            reader.BaseStream.Seek(filePos, SeekOrigin.Begin)
            filePos = reader.BaseStream.Length
            txtContent.Text = reader.ReadToEnd
            If txtContent.Text.Length > 0 Then CrunchRecordByLines(txtContent.Text)
            reader.Close()

i will looping the same function above and get the file line information.

Because of that reason, I need to do a testing, try to open my program and open the text file above, and write some new value inside into new line.

But it cause me the above errors.

**If i close my program, the text file no problem at all and can save.

Hope you all can help.
 
I suggest you call reader.Dispose() before you attempt to attach a Writer to this file. I also recommedn that you close the reader before you CrunchByLines()
 
reader.Close() already calls Dispose(), but I don't see the lock from that code. It could be the CrunchRecordByLines method?
 
Back
Top