[.net] C# Winforms Main method question.....

Started by
4 comments, last by Rob Loach 18 years, 7 months ago
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

[STAThread]
static void Main(string[] args)
{
    ........
}

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?
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Advertisement
Quote:
the path and filename in one param ie [0] = C:\...\...\text.txt
Thank you that is what I thought it did.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
You can use the Path.GetFileName() and Path.GetDirectory() methods to extract the individual components, if you need that.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
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
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
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());}
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement