Default Program Won't Open File

213 views Asked by At

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?

1

There are 1 answers

0
kennyzx On

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.