2 Replies - 2570 Views - Last Post: 06 November 2012 - 02:12 PM Rate Topic: -----

#1 TelcoJoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 28-May 10

Reading .Dat file modifications

Posted 05 November 2012 - 09:29 PM

I have a program that writes information to a .dat file. When I open this file with notebook I can see that for every entry, it generates data on a new line. What I would like to do is monitor the file for new lines of data and display the information in a text box using C#. Would StreamReader.ReadLine be the right method to use?

Thank you.
Is This A Good Question/Topic? 0
  • +

Replies To: Reading .Dat file modifications

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3548
  • View blog
  • Posts: 10,986
  • Joined: 05-May 12

Re: Reading .Dat file modifications

Posted 06 November 2012 - 06:25 AM

View PostTelcoJoe, on 05 November 2012 - 08:29 PM, said:

I have a program that writes information to a .dat file. When I open this file with notebook I can see that for every entry, it generates data on a new line.

Did you mean notepad instead of notebook?


View PostTelcoJoe, on 05 November 2012 - 08:29 PM, said:

What I would like to do is monitor the file for new lines of data and display the information in a text box using C#. Would StreamReader.ReadLine be the right method to use?

Not really. The truly correct way to do things is to understand the data format of that particular .DAT file. It's possible, but not likely that file is a plain text file.

If you really know that it is a plain text file, then ReadLine()'s will work. You'll have to register for file change notifications using the FileWatcher, and then you'll have find the new lines by remembering the previous file size. You could be inefficient and just always read all the lines.

If it's not really a text file, and you just happened to see some strings due to notepad showing you the legible strings, you'll have again register for file change notifications, and then actually read the file using the file format/structure information that you have.

All of the above assumes that the program writing out the .DAT file:
- is not locking the file for exclusive access
- is not re-writing data into "older" sections of the file
- is not caching data to be written out
and that you know the text encoding of the strings you want to display.
Was This Post Helpful? 1
  • +
  • -

#3 TelcoJoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 28-May 10

Re: Reading .Dat file modifications

Posted 06 November 2012 - 02:12 PM

Thanks. That's what I was looking for.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1