open from dskop

P

Pascal Cloup

Hello,

What to do so that when a user double click on a file which extension is
recognised by my application, my application starts and opens this file?

I made an installer that create the expected file association, but when i
double click on a file whith the correct extension, my application is
launched but he file not opend.

Someone can help?

Pascal
 
G

Guest

When you double click an "associated" file, it passes the path of the
associated file to the associated program as an argument. You have to handle
this argument in your application.

An example would look like:

using System;
using System.IO;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
public Form1(string[] args)
{
if(args.Length>0 && File.Exists(args[0]))
{
MessageBox.Show(String.Format("TODO: Implement code to open the
'{0}' file.", args[0]);
}
}

public static void Main(string[] args)
{
Application.Run(new Form1(args));
}
}

In the VS.NET IDE, you can "pass" command line arguments to the application
by doing the following:

Open up the Project's Properties Dialog Box. In the "Configuration
Properties" section, select "Debugging". In the "Start Options" section,
specify the desired file's path in the "Command Line Arguments" section.

Hope that helps.
 
P

Pascal Cloup

Hello Jason,

Thank you very much for your advices.

I have just try it and it works fine (after analyzing the args, because .net
creates a new arg each time it encounter a space caracter ).

It remains just one question in my mind. In the installer project, i created
a file association and i have associated an action to my file type; this
action has a property called "Verb" to which i have afected the value "open"
as it is suggested in the documentation. What is the role of this property
and how to use this property in my application?

thanks again in advance

Pascal
 

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