Native file extension. Double-clicking does not process the file path.

I managed to create my own file extension by following this guide: http://www.codeproject.com/Articles/17023/System-File-Association

So far, this works fine. I have only one thing that I can not solve. When I double-click on a file with this extension, my program opens. Now I want to perform an action in my program. I went through some topics here and read that the file path is automatically passed to the startup arguments.

The problem is that no argument is passed, also Process.GetCurrentProcess (). StartInfo.FileName returns an empty string. I think this is consistent, because I do not pass any arguments when double-clicking on my file.

This is my code:

var fai = new FileAssociationInfo(".extension");
if (!fai.Exists)
{
   try
   {
      fai.Create("My Extension Program");

      var pai = new ProgramAssociationInfo(fai.ProgId);
      if (!pai.Exists)
      {
          pai.Create("My Program File",
          new ProgramVerb("Open", Application.ExecutablePath);
          pai.DefaultIcon = new ProgramIcon(Application.ExecutablePath);
      }
    }
 }

As you can see, I only go the way to it to open it. But how can I pass the file path as an argument now? I saw this, for example, the author of the article passes "% 1" as an argument, I also tried it, but nothing has changed.

Thanks in advance.

+4
source share
2 answers

, . ClassesRoot: "ProgramName\shell\open\command". , , "% 1", .

+2

ProcessStartInfo.FileName , , Windows, .

Process, Process.GetCurrentProcess().StartInfo.Arguments , . , .

, - , Main() static void Main(string[] args){}. args , , .

%1 , (args[0]) .

+2

Source: https://habr.com/ru/post/1569705/


All Articles