executing program by clicking on an associated file (ext)

M

Marco Martin

Good Day Group,

I'm trying to make my application open and run some code when a user clicks
on a file with an associated extension. This is *my* understanding of what
actually happens, please correct me if I am wrong. I've searched the net,
but there doesn't seem to be much on the subject.

1) When using the DotNetPackager (called dotfuscator I believe), we can
associate files with a specific extension to a specific program. Basically
just a registry key being written. Perhaps there is a way to check this
through code and actualy write to the registry if there was a mistake?

2) when a user clicks on an associated file, its like a command line
argument i.e.: "myApp.exe" "c:\myPath\myFile.aaa".

3)In order to use the file, the Main() must accept Args. ie"static void
Main(string[] Args) at which point I can access the filename by accessing
the Args[0] of the Main and store it in a variable in my program.

Please let me know if there's anything else I should know about, or if my
understanding is erroneous.

Thanks and best regards,

Marco
 
P

phoenix

Marco Martin said:
Good Day Group,

I'm trying to make my application open and run some code when a user clicks
on a file with an associated extension. This is *my* understanding of what
actually happens, please correct me if I am wrong. I've searched the net,
but there doesn't seem to be much on the subject.

Google returns plenty of hits. Just use " fileassociation "c#" "
1) When using the DotNetPackager (called dotfuscator I believe), we can
associate files with a specific extension to a specific program. Basically
just a registry key being written. Perhaps there is a way to check this
through code and actualy write to the registry if there was a mistake?

Check http://www.mentalis.org/soft/class.qpx?id=5 It contains both a C# and
VB.Net version with examples.
2) when a user clicks on an associated file, its like a command line
argument i.e.: "myApp.exe" "c:\myPath\myFile.aaa".
yes

3)In order to use the file, the Main() must accept Args. ie"static void
Main(string[] Args) at which point I can access the filename by accessing
the Args[0] of the Main and store it in a variable in my program.

No, you still need to use Main() without arguments but then use
Environment.CommandLine to get the commandline data.
Please let me know if there's anything else I should know about, or if my
understanding is erroneous.

Thanks and best regards,

Marco

Yves
 
M

Marco Martin

Thanks Yves,

I managed to get file name by using the code below(it works...) Thanks for
the link on associating extentions, its exacly what I needed.

regards,

Marco

static void Main(string[] Args)
{
string strInputFile = null;
if(Args.length == 1)
{
strInputFile = Args[0];
}
Application.Run(new Form1(strInputFile);
}

public Form1(String strInputFile)
{
initializeComponent();
strLocalVar = strInputFile;
}

private void Form1_Load(object sender, System.EventArgs e)
{
//do stuff
if(strLocalVar != null)
{
//Do file stuff
}
}
phoenix said:
Marco Martin said:
Good Day Group,

I'm trying to make my application open and run some code when a user clicks
on a file with an associated extension. This is *my* understanding of what
actually happens, please correct me if I am wrong. I've searched the net,
but there doesn't seem to be much on the subject.

Google returns plenty of hits. Just use " fileassociation "c#" "
1) When using the DotNetPackager (called dotfuscator I believe), we can
associate files with a specific extension to a specific program. Basically
just a registry key being written. Perhaps there is a way to check this
through code and actualy write to the registry if there was a mistake?

Check http://www.mentalis.org/soft/class.qpx?id=5 It contains both a C# and
VB.Net version with examples.
2) when a user clicks on an associated file, its like a command line
argument i.e.: "myApp.exe" "c:\myPath\myFile.aaa".
yes

3)In order to use the file, the Main() must accept Args. ie"static void
Main(string[] Args) at which point I can access the filename by accessing
the Args[0] of the Main and store it in a variable in my program.

No, you still need to use Main() without arguments but then use
Environment.CommandLine to get the commandline data.
Please let me know if there's anything else I should know about, or if my
understanding is erroneous.

Thanks and best regards,

Marco

Yves
 

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