Errr... I have a text editor i made, which has been working perfectly for the past month without any problems. But today, and all of yesterday, everytime i open a txt file from explorer (doubleclicking it) instead of it opening in my editor, a message appears saying:
Text Editor has encountered a problem and needs to close. We are sorry fofr this inconvenience. [Send error report] or [Don't send].
When I click on "What does this error report contsin", it shows the following:
EventType : clr20r3 P1 : texteditor.exe P2 : 1.0.0.0 P3 : 4ad32c52
P4 : mscorlib P5 : 2.0.0.0 P6 : 492b834a P7 : 343f P8 : d8
P9 : system.io.filenotfoundexception
So that basically tells me that its looking for a file that doesn't exist. But here's my problem:
The file i am trying to open DOES exist because I just double-clicked on it :P
and... The program itself also does exist, and the computer knows it exists, because it tried to open it.
Another thing... It is NOT possible that the program is trying to open another file on Form_Load, because I didn't make it that way. So, WHAT THE!!!???
Has anybody had this problem before? Can anybody please help?
edit i can open other files by double-clicking them, just not txt files (this was working for a whole month up until yesterday.
edit here is the code that opens a file that has been double-clicked on from windows explorer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TextEditor
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length >= 1)
{
Form1 f = new Form1();
f.txt.Text = System.IO.File.ReadAllText(args[0]);
f.txt.Tag = args[0];
Application.Run(f);
}
else Application.Run(new Form1());
}
}
}
Edit:
Okay, so I've edited the above code to display the exception message in a messagebox in a try/catch block if it fails. Now, when the mesagebox is displayed, no matter which directory the file is actually contained in, the message is always the same path: "Could not find file C\Documents". First, There is no "Documents" directory in C:\ - Second, there is no code in my app that points to that directory, and third, I think this may be caused by too many spaces in the filepath, because when i move the txt file to a directory that contains no spaces, such as: "C:\myfile.txt", it opens correctly in my text editor. :( The weird thing is that I've never had this problem before, so that makes me think that the arguments for file association or file extensions or something like that is screwed up for txt files...