Question Locked

Update a Specifice line of TextFile without causing Sharing Violation

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi all,
I'm creating an Application in .net 2.0 which take data from a text File without causing sharing violation and Update a certain line after reading that data.

I Read file using Stream Reader but not able to find any thing by which i can goto specific line number to update Data.
e.g
A
B
XYZ
LMK
LMT

When i read that i want to change A to C.

I required your help in this regard
Thanks

2 replies

by tony hopkinson

Read through the stream and count line breaks (CRLF or LF).
Use Textreader and get it into a string, then split by line end to an Array, ArrayList or List...

However, you seem to designing a classic inflatable dartboard.

On shared access, so could a delete line 7 or insertline six command be issued before amend line 8?
Ie the line 8 the user issued the chnage for is no longer line 8 in the file.

Even with only change functionality change 1 to C followed by an other user change 1 to D is going to confuse the heck out out of one user, depending on what order the reqests are processed.

Either you need an exclusive lock for changes, or you need to drop this line number stuff and have a unique line identifier (e.g. a guid) in the file.

This discussion is closed to new replies.