filestream append and read access at same time?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi,
Is there any setting that I can use to allow the same file to be open
in a filestream in append mode with one process and read in another.
I can see why concurrent appends or write modes wouldn't work but it
seems like maybe a read could coexist with append?

Thanks,
Bob
 
Hi,
Is there any setting that I can use to allow the same file to be open
in a filestream in append mode with one process and read in another.
I can see why concurrent appends or write modes wouldn't work but it
seems like maybe a read could coexist with append?

Take a look at the FileStream constructors that include a FileShare
enumeration value as a parameter.

Pete
 
Sample below for multi acces read and write

i have several multi threaded services and also reader of activity in this
log....

hope this helps

analizer1



if (!File.Exists(LogName.FullName))

{

sw = new FileStream(this.LogName.FullName, FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite);

}

else

{

sw = new FileStream(this.LogName.FullName, FileMode.Open,
FileAccess.ReadWrite, FileShare.ReadWrite);

}
 
Sample below for multi acces read and write

Note that there is a FileMode.CreateOrOpen enumeration value. There's
no need to check for file existence before creating the FileStream; you
can use the same constructor for both scenarios.

Pete
 
Note that there is a FileMode.CreateOrOpen enumeration value. There's
no need to check for file existence before creating theFileStream; you
can use the same constructor for both scenarios.

Pete

Thanks very much. It seems like I had to change a setting from
FileAccess.Read to FileAccess.ReadWrite which seems odd considering I
would think the former would be more restrictive. Thanks again.
 
Thanks very much. It seems like I had to change a setting from
FileAccess.Read to FileAccess.ReadWrite which seems odd considering I
would think the former would be more restrictive. Thanks again.

I'm not sure what you mean. The FileAccess determines how your process
opens the file. The FileShare determines what other processes can do
with a file you've opened.

You would certainly need to open the file with write access if you
expect to be able to write to it, thus the need for
FileAccess.ReadWrite.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top