The title is confusing, I know.
What I mean is, I created a note pad (like) program with line sorting functions. I want to be able to associate .txt files in explorer with the program. Currently I modified the Main function to accept command like arguments. and I modified my constructor for my main form to load the 1st command line argument as a file name, and open it. so if you drag and drop a file onto the icon, it opens. and works. but if you associate the txt file with the program, the program opens, but the document doesn't. I can't find any articles on this, because Im not sure exactly what to search for.
just for clarification. here is my code.
here's the Entry point
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new fclsMain(args));
}
}
here is the overloaded constructor
public fclsMain(string[] args)
{
InitializeComponent();
if (args.Length == 0)
{
currentFile = "";
this.Text = "SortPad: New Document";
}
if (args.Length != 0)
{
{
currentFile = args[0];
System.IO.StreamReader txtReader;
txtReader = new System.IO.StreamReader(currentFile);
txtMain.Text = txtReader.ReadToEnd();
txtReader.Close();
txtReader = null;
txtMain.SelectionStart = 0;
txtMain.SelectionLength = 0;
txtMain.Modified = false;
FileInfo file = new FileInfo(currentFile);
this.Text = "SortPad: " + file.Name;
}
catch {
currentFile = "";
this.Text = "SortPad: New Document";
}
}
}
}
What am I doing wrong?
Is there something that windows adds to the argument when opening a document?
HELP!