read file without locking it.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VB.Net 2003
Hi,
2 questions:
1. I want to read a file in without locking it, as it is Log file.
2. I want to be able to read from the last point it wa read upto.

The project is:
Search through ftp log files for certain files download to our ftp site.
This will be on a schedule so I would like to pass to my database the point
(in bytes) where I have read upto. Then next time I check it I want to only
ready from the amount of bytes recalled from the database.

Writing the filedetails and retrieving the file details to the Db are not a
problem, just how to go about reading the file in the manor described above.

regards
John.
 
John said:
VB.Net 2003
Hi,
2 questions:
1. I want to read a file in without locking it, as it is Log file.
2. I want to be able to read from the last point it wa read upto.

The project is:
Search through ftp log files for certain files download to our ftp site.
This will be on a schedule so I would like to pass to my database the point
(in bytes) where I have read upto. Then next time I check it I want to only
ready from the amount of bytes recalled from the database.

What have you tried and what problems are you having? The StreamReader
can be used to read the file as well as opening it for read access only
without locking it. Also, it allows for seeking into the file to a
certain point.

What problem are you experiencing?
 
Thanks Chris,
The problem I am experiencing was basically which way to go. I had not
coded anything as yet to read the file, but now you have said StreamRead will
suit my needs I will delve into this an try to put some code together.

For the few projects I have done I have used
myfileobject.opentextfile(c:\.......)

I see in help there is an example of StreamRead:

' Open the stream and read it back.
fs = File.Open(path, FileMode.Open, FileAccess.Read)
Dim b(1024) As Byte
Dim temp As UTF8Encoding = New UTF8Encoding(True)

Do While fs.Read(b, 0, b.Length) > 0
Console.WriteLine(temp.GetString(b))


If I run into problems with it then you will no doubt hear from me.

Thanks for the prompt response, I will start tomorrow with fresh eyes.
 
"John please don't spam me!"
1. I want to read a file in without locking it, as it is Log file.

Open the 'FileStream' with 'FileShare.ReadWrite' specified, which will allow
other applications to read and write to the file while your application is
keeping it opened.
 
Thanks Herfield, I saw this in help and was thinking of trying it. I am
thinking no longer after your response - I will us it, thanks.
 
Back
Top