I am trying to open a Word file for reading using FileStream in C #. I hacked a quickfetch application consisting of a text box and a button to start creating a stream. The sample code to open the file is as follows:
if (File.Exists(this.TxtPath.Text)) { Stream s = new FileStream(this.TxtPath.Text, FileMode.Open, FileAccess.Read, FileShare.Read); }
When I try to open a Word file that is already open in Word, I get a System.IO.Exception message saying that the file is already open by another process and cannot be opened.
When I try to open the same file in Notepad ++, when it is open in Word, it works without problems. Therefore, in principle, this should be possible.
Is there something I forgot?
Quick edit: I use Word 2007 and VisualStudio 2008 if that helps. Version .NET Framework 3.5.
source share