How to open a file from a C # code through a program (that is, third-party) that is not associated with this type? For example, I need to open the file "c: \ 1.pdf" from the program with the program "c: \ program.exe", with which it does not work like this: Process.Start("c:\program.exe", "c:\1.pdf"); or Process.Start("c:\program.exe c:\1.pdf");

    1 answer 1

    Looking at all,

     Process.Start(@"c:\program.exe", @"c:\1.pdf"); 

    (pay attention to @ ).

    At the same time, the c:\program.exe should, of course, support file transfer on the command line. If additional keys are needed for this program, you must also transfer them.

    • I tried the variant with Process in all possible ways. The program itself, apparently, does not accept the file as an argument, so it does not fit. But is it possible to achieve discovery in other ways (special utility, library, code)? - Nikolay
    • @Nikolay: Well, then you will find out from the very beginning: how exactly the program takes command line arguments, and whether it accepts at all. There is no general way, it all depends only on the desire of programmers. For example, if the programmer has not written any code that looks at the command line, then, of course, it will not affect anything. - VladD
    • You can, of course, temporarily change the file associations through the registry: make pdf associate with this program, but then you need to restore the original associations, and the registry says just "acrobat.exe", and not the full path to the program. - Nikolay
    • Apparently he doesn’t accept anything, this is the whole snag. In this program, only drag drop'om drag pdf, then it opens it. - Nikolay
    • @Nikolay: Well, you would have searched the program documentation. Or would ask the authors. We here, not knowing what the program is, are unlikely to help. (Yes, and knowing, all the same questions about the format of the command line are here on the verge of oftopika.) - VladD