Home > Software engineering >  When a file is "opened with" a winforms application how do I get the application to load t
When a file is "opened with" a winforms application how do I get the application to load t

Time:02-06

I am able to set my .mdb files to "open with" my winforms application, but that only opens the winforms application without loading the file. Is there any event that is triggered upon opening the application through a file for me to add how my application will react to the file/file-directory?

CodePudding user response:

When you double-click an mdb file, your application will be executed with mdb file argument. Similar to calling your app from command line:

> your-app.exe "test.mdb"

You should use the args in the Main method.

class Program
{
    static void Main(string[] args)
    {
        // check that user provided a file to open
        if (args != null && args.Length > 0)
        {
            var mdbFilePath = args[0];
            // TODO: read the file
        }

        // ...
  •  Tags:  
  • Related