Search code examples
c#arguments

How do I get arguments in a form application?


I can find many examples on how to get arguments in a console application, but I can't seem to find an example of how to get arguments in a windows form application.

I would like to following things.

  1. whenever I open a jpg file, windows launches my application.
  2. I would like to know path and name of the jpg file from my application.

How do i do that?


Solution

  • You can get the command line arguments as a string array using Environment.GetCommandLineArgs().

    You use it as such:

    string[] args = Environment.GetCommandLineArgs()