Open file with association

associations, c#, file, file-extension

Solution

In windows file associations are stored and managed in the registry under `HKEY_CLASSES_ROOT`

You can do the following manually or eventually write a little setup program to write the correct entries to the registry.

You need to register your extension and then associate it with a program like this document describes. Also see this doc Your registry should look like this:

HKEY_CLASSES_ROOT
   .nlp
      (Default) = YourProgID//can by anything you want
   YourProgID
      shell
         open
            command
               (Default) = yourapp.exe %1

Now, they key to your answer is the `%1` in the command key. It is the filename that was opened and it passed as an argument to you app.

So :

static void Main(string[] args)
{
   // args will contain your filename
}

Problem

i made a file editor in C#, and i can open files using the 'Open' button in the toolbar, i also associated the correct file types to the program, so when i click a file with the extension *.nlp the program opens correctly, but does not open the file itself (which is quite logical since i did not implement it yet) now is my question, how do i implement such a thing? i want the file to be opened and loaded when i click on it. (btw, the file is just plain text, so nothing special, and it's for windows if that matters)

Original source

Related problems