.NETGURU
Help - Continuous file reading!
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Marty
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
Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* Marty <Click here to reveal e-mail address> scripsit:
[Original message clipped]

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/>
Reply to this message...
 
    
Marty
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:

[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* Marty <Click here to reveal e-mail address> scripsit:
[Original message clipped]

'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/>
Reply to this message...
 
    
Marty
Marvelous! thanks you. :)

Herfried K. Wagner [MVP] wrote:
[Original message clipped]

Reply to this message...
 
 
System.IO.FileAccess
System.IO.FileMode
System.IO.FileShare
System.IO.FileStream
System.IO.StreamReader




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification