[STAThread]
static void Main(string[] args)
{
........
}
[.net] C# Winforms Main method question.....
Ok I have been wondering this for a while. Say I write a Text Editor in WinForms and C#. Now someone associates my text editor with text files. So that when the text file is double clicked it opens it in my editor. Now obviously windows is going to pass a param and or params to my exe file. This means I must use
Ok I understand that much. My question is what does windows pass into the args array. Is it the path and filename in one param ie [0] = C:\...\...\text.txt or does it pass [0] = C:\...\...\...\ [1] = text.txt?
You can use the Path.GetFileName() and Path.GetDirectory() methods to extract the individual components, if you need that.
Thanks I know alot about .Net just never really messed about with the args passed into main as I never needed too :P. I have a project in the works now that needs to lol however, it is not a text editor. And i will not say what it is. When the time is right you all will know :P
The best way to learn is trial and error. Do some of your own tests:
[STAThread]static void Main(string[] args){ MessageBox.Show(args[0]); FileInfo file = new FileInfo(args[0]); MessageBox.Show(file.ToString());}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement