How do you open a file from outside program?  
Author Message
Zados Maerc





PostPosted: Visual C# General, How do you open a file from outside program? Top

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"

Visual C#6  
 
 
Zados Maerc





PostPosted: Visual C# General, How do you open a file from outside program? Top

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


 
 
Prasant Swain





PostPosted: Visual C# General, How do you open a file from outside program? Top

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());

}

 



 
 
ahmedilyas





PostPosted: Visual C# General, How do you open a file from outside program? Top

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