how to write to file that is open

Jordan Halgunseth 1 Reputation point
2023-02-04T13:18:16.3966667+00:00

My program writes to a file.

The user can needs to be able open file read it.

This gives an error, when trying add more data to file

This is for C#

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 111.5K Reputation points
    2023-02-04T17:09:30.5466667+00:00

    If one program opens a binary file in this manner:

    FileStream s = new FileStream( @"C:\MyFiles\file1.bin", 
       FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
    
    s.Write( . . . );
    s.Flush();
    
    

    then another program can read it:

    FileStream s = new FileStream( @"C:\MyFiles\file1.bin", 
       FileMode.Open, FileAccess.Read, FileShare.ReadWrite );
    
    s.Read( . . . );
    
    0 comments No comments