Opening files with associated applications?

M

mrabie

Hi all,

I am writing a file explorer application for PocketPC, i use
Systems.Diagnostics Process to start application, but is there a way
to when i click on an image/doc/xls it automatically opens it with the
associated app (image viewer/pocket work/pocket excel,etc)?

I try to pass the file name as the parameter to the Process.Start but
it returns an error

Thanks for your help
 
P

Paul G. Tobey [eMVP]

If nothing else, you could P/Invoke ShellExecuteEx(). That's what the
Explorer shell does (of course, it's native code, so there may be some
wrapper in managed code that I'm not thinking of), when you tap on a
non-executable file.

Paul T.
 
C

Christopher Fairbairn

Hi,

mrabie said:
I am writing a file explorer application for PocketPC, i use
Systems.Diagnostics Process to start application, but is there a way
to when i click on an image/doc/xls it automatically opens it with the
associated app (image viewer/pocket work/pocket excel,etc)?

Try using the start info property:

Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(@"\path\to\file.doc", "");
p.StartInfo = startInfo;
p.Start();

This will internally use the native ShellExecuteEx API mentioned by Paul in
another reply to your thread. Hence the file association registry enteries
will be utilised to find the application associated with these files.

Hope this helps,
Christopher Fairbairn
 
A

Arun

You can very well do it using ProcessStartInfo class. Below is a
snippet

Process myProcess = new Process();
myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
myProcess.Start();

my.StartInfo.UseShellExecute is another property by default will be
true will start the document in the associated editor.
if it is set to false, the process is created directly from the
executable file.

Hope this helps,
Cheers,
Arun
 

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