Getting args array from files launch through file association

G

Guest

I've got a process engine written in .Net. the user writes a data file and
saves it as file type ".xyz". I have a file assiciation set up in the
database that when a .xyz file is invoked (double click or called in cmd
prompt) it passed to my process engine executable as a cmd line parm.

so the process engine gets one argument, which is the path to the .xyz file.
this is standard stuff.

what i'd like to do is call the .xyz file via the command prompt and pass in
several input parms. like so:

myfile.xyz thing1 thing2 thing3

when this gets executed, the process engine should get an arg array (in the
Main function) that has 4 elements. the first one is the path, and the last
three are the arguments.

But, the process engine only gets the path. thing 1-3 are lost.

is there anyway i can get these items in the arg list for the Main function?

the only way i can think is to get rid of the file assiciation and you have
to call the engine exe with the path of the data file as the first arg, and
all other arguments later. I'd really rather not do this though.

thanks
 
G

Guest

Hi John...
Sorry because I don't speak English very well but I will try to show my
suggestion:

You can create a Process object and pass in those parameters. See the
example below:

Process myProcess = new Process();
myProcess.StartInfo.FileName = "myfile.xyz";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.Arguments = "thing1 thing2 thing3";
myProcess.Start();

You can build the string with all arguments then you get the file path.
See more about Process class.

Test the example below (create two console applications):

Caller Program:
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample{

public class MyProcess{
public static void Main(){

Process myProcess = new Process();
myProcess.StartInfo.FileName = "c:\\temp\\ConsoleApplication10.exe";
myProcess.StartInfo.Arguments = "teste1";
myProcess.Start();

}
}
}

Called program:
using System;

namespace ConsoleApplication10{
class Class1{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(args[0]);
Console.ReadLine();
}
}
}


bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top