473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Read/Loop Textfile when it is used by another process

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
3 2189
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our...
4
by: funkmusha | last post by:
I am trying to read a log file using vb.net. I get an error stating "The process cannot access the file 'C:\test.log' because it is being used by another process." Below is a sample of what I am...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
9
by: Justme | last post by:
Novice programmer needs help with using fgets to read and ignore the first two lines of a file. I've gone thru the previous posting regarding fgets, but none of them seems to help my situation. I...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
1
by: | last post by:
Hello everybody, i need your help : i have to write some lines coming from a database into a textfile; Everything goes right while the filesize is quite small or medium; But it's different when...
0
by: Snoze | last post by:
Hello, I'm trying to make an application with C# that writes and reads some lines of a text file, but I want to read one specific line and save the text in a string variable. And the inverse...
3
by: Ryan Liu | last post by:
Will TcpClient.GetStream().Read()/ReadByte() block until at least one byte of data can be read? In a Client/Server application, what does it mean at the end of stream/no more data available? ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.