Cannot open a file in use by another application (SE 3.1)

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
I haven't tried this in SE 4.0, but it's consistent with SE 3.1 in the sample app. I have an application that is constantly writing to HTML formatted log files. I can open these files in Notepad, TextPad, WordPad, etc, without any problem. When I try to open the file using SE, I get an IOException.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.IOException: The process cannot access the file "\\nadcwpappqcr01\QualityCenter\log\sa\SaServerLog_2006_10_11_01_28_33_999.html" because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
   at System.IO.File.OpenText(String path)
   at ActiproSoftware.SyntaxEditor.Document.LoadFile(String path)
   at TestApplication.MainForm.ExecuteAppAction(AppAction action) in C:\Program Files\Actipro Software\SyntaxEditor\v3.1.0210\TestApplication-CSharp.Net11\MainForm.cs:line 3617
   at TestApplication.MainForm.toolBar_ButtonClick(Object sender, ToolBarButtonClickEventArgs e) in C:\Program Files\Actipro Software\SyntaxEditor\v3.1.0210\TestApplication-CSharp.Net11\MainForm.cs:line 2322
   at System.Windows.Forms.ToolBar.OnButtonClick(ToolBarButtonClickEventArgs e)
   at System.Windows.Forms.ToolBar.WmReflectCommand(Message& m)
   at System.Windows.Forms.ToolBar.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Is there any way to get SE to properly read a file that is in use by another process?

FYI, this may be a symptom of the .NET Framework. I've tried a few different ways to open a text file in use by another process, and I can't get it to work. Any ideas?

[Modified at 10/11/2006 03:49 PM]

Comments (3)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Our code is pretty simple... see below... we can change it as needed if you find a solution:
StreamReader reader = File.OpenText(path);
string text = reader.ReadToEnd();
reader.Close();


Actipro Software Support

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Also FYI if you use Reflector to trace it down, that ends up calling this:
Stream stream1 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 0x1000, FileOptions.SequentialScan);


Actipro Software Support

Posted 17 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Avatar
I figured that was the code you were using, so I was trying to come up with a proper combination of options to make it work. I can't get it to open the file either. Seems odd that this is easy enough to do (since Notepad can do it), but the .NET Framework doesn't provide a simple method to accomplish the same thing. I'll keep you posted if I find anything out. I was hoping someone might see this and know the silver bullet solution.
The latest build of this product (v24.1.0) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.