icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.86k stars 470 forks source link

OpenFile fails to open text file with 4 character file extension #360

Closed raymrdc closed 2 years ago

raymrdc commented 2 years ago

using the following command fails if filename have file extension of 4 characters (example: sample.txta)

StreamReader file = ICSharpCode.AvalonEdit.Utils.FileReader.OpenFile(filename, Encoding.Unicode)

siegfriedpammer commented 2 years ago

Looking at the code, I don't see how the file extension could cause problems. Maybe the file you are trying to open does not exist at all?

I tried this code, with 2 files that contain the text "TextFile1.txt" and "TextFile2.txta" respectively.

            var s1 = ICSharpCode.AvalonEdit.Utils.FileReader.OpenFile("TextFile1.txt", Encoding.Unicode).ReadToEnd();
            var s2 = ICSharpCode.AvalonEdit.Utils.FileReader.OpenFile("TextFile2.txta", Encoding.Unicode).ReadToEnd();
            MessageBox.Show(s1); // shows contents of TextFile1.txt
            MessageBox.Show(s2); // shows contents of TextFile2.txta
raymrdc commented 2 years ago

Hi, Thanks for the quick response. You can close this issue. After further investigation, my app reads the file twice which cause the error for filename with 4 char extension.

I wonder why the file with 3 char extension works successfully even though it goes through the same code but fails when the extension is 4 char.