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

Read/Loop Textfile when it is used by another process

P: n/a
Hi all

I am trying to loop a Textfile.
This Textfile is located on a shared drive and it is
used by another process.

When I try to read it I get an exeption:
The process cannot access the file 'file.log' because it is being used by
another process.

I am opening like:
System.IO.FileStream local_FileStream = new System.IO.FileStream("File.log",
System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);

How can I open a file when it is open ??
For example, I can open this file with Notepad ...

Thanks for any comments
Best regards
Frank

Sep 1 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Frank Uray" <Fr*******@discussions.microsoft.comwrote in message
news:74**********************************@microsof t.com...
Hi all

I am trying to loop a Textfile.
This Textfile is located on a shared drive and it is
used by another process.

When I try to read it I get an exeption:
The process cannot access the file 'file.log' because it is being used by
another process.

I am opening like:
System.IO.FileStream local_FileStream = new
System.IO.FileStream("File.log",
System.IO.FileMode.Open, System.IO.FileAccess.Read,
System.IO.FileShare.Read);
The meaning of FileShare is not what you intend to do with the file, it's
what you want to allow other programs to do with the file while you keep it
open. So, FileShare.Read means that you only allow other programs to read
the file, and not write it. Since another application is already writing to
it, your request is denied. Try using FileShare.ReadWrite instead.
Sep 1 '08 #2

P: n/a
Hi

Thanks a lot, this was it.

By the way, do you know how to read the lines
from the file beginning at the end of the file ??

Best regards
Frank

"Pavel Minaev" wrote:
"Frank Uray" <Fr*******@discussions.microsoft.comwrote in message
news:74**********************************@microsof t.com...
Hi all

I am trying to loop a Textfile.
This Textfile is located on a shared drive and it is
used by another process.

When I try to read it I get an exeption:
The process cannot access the file 'file.log' because it is being used by
another process.

I am opening like:
System.IO.FileStream local_FileStream = new
System.IO.FileStream("File.log",
System.IO.FileMode.Open, System.IO.FileAccess.Read,
System.IO.FileShare.Read);

The meaning of FileShare is not what you intend to do with the file, it's
what you want to allow other programs to do with the file while you keep it
open. So, FileShare.Read means that you only allow other programs to read
the file, and not write it. Since another application is already writing to
it, your request is denied. Try using FileShare.ReadWrite instead.
Sep 1 '08 #3

P: n/a
"Frank Uray" <Fr*******@discussions.microsoft.comwrote in message
news:26**********************************@microsof t.com...
By the way, do you know how to read the lines
from the file beginning at the end of the file ??
Seek to the end of FileStream you've opened, and only then create a
StreamReader wrapping it.
Sep 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.