How do you open a file from outside program?

I've made a program that handles text files and I want to be able to right click on a text file, and go to "Open With > MyProgram.exe" and have my program open it up. Currently when I do this it just opens my program, can anyone get me started or tell me what I have to do to get my program to respond to "Open With > My Program.exe"

Answer this question

How do you open a file from outside program?

  • ashok-or

    if you mean in terms of running a process then you need to use the Process class in System.Diagnostics namespace to kick off that file:

    System.Diagnostics.Process.Start("path\filename.ext");

    you can also further customize the way the process should start, give parameters and redirect inputs and outputs using the assistant class, ProcessStartInfo:

    http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx



  • Tengu

    you can do like this

    static void Main(string[] args)

    {

    'args[0] : it will return the full file path you try to open . then you can do as needed to show the file.

    Application.EnableVisualStyles();

    Application.SetCompatibleTextRenderingDefault(false);

    Application.Run(new frmMain());

    }

     



  • Raulsassaa

    After a ton of searching I found the answer; just have to use Environment.Commandline to get the filename and handle it.


  • How do you open a file from outside program?