Open file with association

I created a file editor in C #, and I can open files using the "Open" button on the toolbar, I also linked the correct file types to the program, so when I click on the file with the * .nlp extension, the program opens correctly, but the file itself does not open (which is quite logical, since I have not implemented it yet)

Now my question is, how do I implement such a thing? I want the file to be open and downloaded when I click on it.

(btw, the file is just plain text, so nothing special, and this is for windows, if that matters)

+5
source share
3 answers

Windows file associations are stored and managed in the registry under HKEY_CLASSES_ROOT

, , .

, . . :

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

, : %1 . , .

:

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

API- .Net , , .

HKEY_CLASSES_ROOT , (: ".txt" ). , "Acme.TextFile". HKEY_CLASSES_ROOT , "Acme.TextFile". "DefaultIcon" , , . , "". "shell" , "", , "% 1", .

, TXT EmEditor:

Windows 5.00

[HKEY_CLASSES_ROOT\.txt]
@="emeditor.txt"

[HKEY_CLASSES_ROOT\emeditor.txt]
@="Text Document"

[HKEY_CLASSES_ROOT\emeditor.txt\DefaultIcon]
@="%SystemRoot%\\SysWow64\\imageres.dll,-102"

[HKEY_CLASSES_ROOT\emeditor.txt\shell]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\open]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\open\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\emeditor.txt\shell\print]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\print\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" /p \"%1\""

@X-Cubed

+2

:

public static void Main(string[] args)
{
  if ( args != null && args.Length > 0 )
  {
    string filename = args[0];
    if ( File.Exists ( filename ) )
    {
      //Open file 
    }
  }
}
+2

All Articles