-2

I've written a program in C# that creates and opens files in a proprietary file format. I created the installer using InstallShield Express. The files are created and show up with the appropriate file icon that I have assigned to them.

The files that my program opens and creates open just fine when I run the program and then open the files. But when I go to the directory where the files are located and double-click on them, the program they're associated with starts running, but the files won't open in that program automatically.

When you open a ".doc" file, for example, Microsoft Word starts and the .doc file opens. This is what I want to happen. Am I missing something?

Unihedron
  • 10,902
  • 13
  • 62
  • 72
user2272380
  • 103
  • 1
  • 2
  • 13
  • The file path should have been passed to the program's `Main` method, do you have logic in the `Main` method to handle the parameter, and open the file? – kennyzx Oct 25 '14 at 07:01
  • Unfortunately, I have no such code in my program. I'm kind of new at this practice and I'm not sure what code to write. – user2272380 Oct 25 '14 at 18:16

1 Answers1

0

If you double click the file to launch the associated program, you can get the file path from the arguments passed to the Main method.

static void Main(string[] args)
{
    if ((args.Length > 0) && System.IO.File.Exists(args[0]))
    {            
        string filepath = args[0];
        System.Diagnostics.Debug.WriteLine("File path to open: " + filePath);
    }
}     

And you have code to open a file after it is created, right?

"The files that my program opens and creates open just fine when I run the program and then open the files."

Then what you need to do is to call that piece of code from your Main method.

kennyzx
  • 12,845
  • 6
  • 39
  • 83