469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Help - Continuous file reading!

Hi everybody,

Is it possible to do that in VB.NET: I have a text file that is filled
with new lines of text every n seconds. This text file get very massive.

I want to have my program to monitor this text file and to be able to
read only the new added line when it detect that a new line has been added.

I don't want to read the whole file every time, this would be high time
consuming.

Any idea? Thanks you very much!

Marty
Nov 21 '05 #1
4 2473
* Marty <re***@to.forum> scripsit:
Is it possible to do that in VB.NET: I have a text file that is
filled with new lines of text every n seconds. This text file get
very massive.
I want to have my program to monitor this text file and to be able to
read only the new added line when it detect that a new line has been
added.
I don't want to read the whole file every time, this would be high
time consuming.


Check the file size every n seconds and store the previous file size.
Then you can use the 'FileStream''s 'Seek' method or 'Position' property
to read data beginning at the position where the file ended the last
time you read it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Thanks Herfried,

It work very well.

I have another question, how can I be sure that by reading the file, I
don't interrupt the other process who want to add a text line to it?

This is my reader object settings:
Dim fs As New FileStream(strFilePath, FileMode.Open, FileAccess.Read)
Dim ioFileIN As StreamReader = New StreamReader(fs)

Is there anything else that I can set to have my ioFileIN not holding
the file while reading?

Thanks

Marty

Herfried K. Wagner [MVP] wrote:
* Marty <re***@to.forum> scripsit:
Is it possible to do that in VB.NET: I have a text file that is
filled with new lines of text every n seconds. This text file get
very massive.
I want to have my program to monitor this text file and to be able to
read only the new added line when it detect that a new line has been
added.
I don't want to read the whole file every time, this would be high
time consuming.

Check the file size every n seconds and store the previous file size.
Then you can use the 'FileStream''s 'Seek' method or 'Position' property
to read data beginning at the position where the file ended the last
time you read it.

Nov 21 '05 #3
* Marty <re***@to.forum> scripsit:
I have another question, how can I be sure that by reading the file, I
don't interrupt the other process who want to add a text line to it?
This is my reader object settings:
Dim fs As New FileStream(strFilePath, FileMode.Open, FileAccess.Read)


'FileStream' provides a ctor that accepts a 'FileShare':

\\\
Public Sub New( _
ByVal path As String, _
ByVal mode As FileMode, _
ByVal access As FileAccess, _
ByVal share As FileShare, _
ByVal bufferSize As Integer, _
ByVal useAsync As Boolean _
)
///

Set 'Share' to 'FileShare.ReadWrite'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
Marvelous! thanks you. :)
Herfried K. Wagner [MVP] wrote:
* Marty <re***@to.forum> scripsit:
I have another question, how can I be sure that by reading the file, I
don't interrupt the other process who want to add a text line to it?
This is my reader object settings:
Dim fs As New FileStream(strFilePath, FileMode.Open, FileAccess.Read)

'FileStream' provides a ctor that accepts a 'FileShare':

\\\
Public Sub New( _
ByVal path As String, _
ByVal mode As FileMode, _
ByVal access As FileAccess, _
ByVal share As FileShare, _
ByVal bufferSize As Integer, _
ByVal useAsync As Boolean _
)
///

Set 'Share' to 'FileShare.ReadWrite'.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Marty | last post: by
13 posts views Thread by Jeff Pritchard | last post: by
2 posts views Thread by Phil Stanton | last post: by
1 post views Thread by blueheelers | last post: by
7 posts views Thread by capnwhit | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.