By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

read file without locking it.

P: n/a
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.
--
Kind Regards
John.
Sep 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
John please don't spam me! wrote:
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?

Sep 19 '06 #2

P: n/a
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.
--
Kind Regards
John.
"Chris Dunaway" wrote:
John please don't spam me! wrote:
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?

Sep 19 '06 #3

P: n/a
"John please don't spam me!"
<Jo******************@discussions.microsoft.comsch rieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 19 '06 #4

P: n/a
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.
--
Kind Regards
John.
"Herfried K. Wagner [MVP]" wrote:
"John please don't spam me!"
<Jo******************@discussions.microsoft.comsch rieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.