473,396 Members | 1,693 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,396 software developers and data experts.

Sharing an open file between processes

So I have a log file that I'm writing with one C# program and want to open
and read it in another one. I open it via :

StreamWriter log = File.AppendText(logPath);
log.AutoFlush = true;

but when I try to read it with another application, for instance, like :
StreamReader log = new StreamReader(logPath);
String logContents = log.ReadToEnd();
log.Close();

it fails complaining about it already being open by another application. Is
it possible to share a file between two processes such that one can be
writing to it and another can read from it? I'm not too concerned about
race conditions (like what happens if the reader catches the writer in the
middle of writing a buffer).

Thanks,
Doug Wyatt
Nov 15 '05 #1
1 4595
You can share a file by setting the proper Share flags.

In the read-app, use,

File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.Read);

In the write-app, use,

File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Write);

vJ

"Doug Wyatt" <ne*********@starbak.net> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
So I have a log file that I'm writing with one C# program and want to open
and read it in another one. I open it via :

StreamWriter log = File.AppendText(logPath);
log.AutoFlush = true;

but when I try to read it with another application, for instance, like :
StreamReader log = new StreamReader(logPath);
String logContents = log.ReadToEnd();
log.Close();

it fails complaining about it already being open by another application. Is it possible to share a file between two processes such that one can be
writing to it and another can read from it? I'm not too concerned about
race conditions (like what happens if the reader catches the writer in the
middle of writing a buffer).

Thanks,
Doug Wyatt

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mladen Gogala | last post by:
How can I share variables between two processes? Here is my problem? File test1.php: ------------------------------------------------------------------- <?php session_start(); $var1="This...
4
by: Tony Liu | last post by:
Hi, how can I create multiple new file handles of a file without having to share to file to the other processes? I have a file that will be accessed by multiple threads in my application, each...
4
by: et | last post by:
I have an aspnet program that uses an Access database -- I won't go into why I'm using Access -- and can't get it to run in share mode. If I have opened the website, and I try to edit the...
3
by: Denis Correard | last post by:
Is there a way to find out if a file, say a TXT file, is already open by another user/application in VB.net? I tryed to look at "Stream", "FileInfo" but without success. I need to know because...
1
by: bruce.1 | last post by:
I'm trying to figure a way for a remote user -- using ASP.NET -- to share files on a local office LAN. The remote user would go to an ASP.NET website (on the LAN), mark the files they want, and...
6
by: Rajesh | last post by:
Hi, We are tyring to build a DLL which will write the log data to a text file. Multiple executables should use this dll to write data to same text file. We are using a synchronized method...
11
by: Max Vit | last post by:
I have deployed few Access apps splitting it in Front End and Back End. Our environment uses Win XP SP2 for clients, Win 2k3 for servers and Access 2003. The max. number of clients is about 50...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
9
by: Peri | last post by:
Dear All, Is there a way in which 2 application can share a common memory location to access static data? Say for example I have a product master data that is available in a single place, and...
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:
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.