0

I just finished this tutorial - Create a Picture Viewer - on the MSDN site, and it all works well according to the tutorial specifications (although I did remove the unnecessary buttons).

At the moment, I can open an image file from within the program, which is fine. However, I'd like to be able to open an image file from Windows Explorer, and have it open in my Image Viewer. (Using the Open With.. context menu).

I did try and open it via the Open With.. menu, but when the program loaded, the image didn't show up. The program just started up as it normally would.

What code do I need to put in, that allows me to open the program via an image file (if that makes sense)

2
  • 1
    There are two parts to this 1) the installer makes the necessary registry changes to register the file associations and 2) you need to handle the file name (passed as a parameter to your Main method) so that you can open it. What are you using as your application installer? Commented May 4, 2012 at 1:41
  • I've used Inno Script Studio to create the installer, and it all installs correctly. And how do I handle the file name in the Main method? Commented May 4, 2012 at 12:17

1 Answer 1

1

You can use:

Environment.CommandLine 

Which will contain stuff in the format of "..." "...", first being the path of your application, and in your case - second would be the path of the opened-with file.

Then, you can split that to get the second "..." and load the file as you normally do in you application.

You can also check to see whether the arguments of the application contain the path of the opened-with file. I'm not sure about that, but it should be very easy to check: Have an mbox which prints the parameters, then try opening a file with your program and see what shows up. Using the args[0] or args[1] or whatever will probably be easier than splitting Environment.CommandLine...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.