C# - FileStream: both lock a file and at the same time be able to read it without truncating it and write it with truncating it
I suppose my title isn't that clear. I'll try to explain: I can write and read a file using a FileStream FileStream fs = new FileStream("C:\\Users\\Public\\text.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); private void button1_Click(object sender, EventArgs e) { fs.Seek(0,0); StreamReader sr = new StreamReader(fs); textbox.Text = sr.ReadToEnd(); } private void button2_Click(object sender, EventArgs e) { StreamWriter sw = new StreamWriter(fs); sw.Write(textbox.Text); sw.Flush(); } This way other programs can't use the file, but I also can't delete content. Writing to it