Opening files with associated applications?

  • Thread starter Thread starter mrabie
  • Start date Start date
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
 
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.
 
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
 
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
 
Back
Top