Cheesus Toast
Cheesus Toast

Reputation: 1073

How do you read the file-path of a file that has been set to open your application by default?

I wish to be able to open my C# forms application (image viewer) with, for example, a jpg or gif. What would I have to do to allow the application to read the file-path of that file so that it can process it accordingly?

The application is working fine; all I need to do now is make sure that it can display a picture immediately if it is set to the default for images like jpg, gif etc.

Upvotes: 1

Views: 65

Answers (1)

giacomelli
giacomelli

Reputation: 7415

You can use Environment.GetCommandLineArgs ();

As the documentation describe:

The first element in the array contains the file name of the executing program. If the file name is not available, the first element is equal to String.Empty. The remaining elements contain any additional tokens entered on the command line.

So, in your case, the image file path that 'starts'your application should be the second element of the array returned by Environment.GetCommandLineArgs ().

Upvotes: 1

Related Questions