0

Been searching a while and can't seem to find any answer to my problem. I want to be able to open a file which is already in use. This is the code I use to open the file with:

OpenFileDialog openFile1 = new OpenFileDialog();


openFile1.Filter = "Text Files|*.log";
openFile1.Multiselect = true;
openFile1.Title = "Open log files";

if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    richTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.PlainText);

_textArray = richTextBox1.Lines;
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Winkz
  • 329
  • 2
  • 5
  • 19

1 Answers1

0

You cannot do this unless the other entity which has the file open allows for shared reads. Therefore, you must open the filestream with the FileShare.ReadWrite parameter.

There are some already answers to this.

http://msdn.microsoft.com/en-us/library/b9skfh7s(v=vs.110).aspx Exception in opening a file that is already open How do I open a file that is opened in another application

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48