Process.Start and unknown file types

M

Marina Levit

I'd like to open up a file programmatically, but if it is not associated
with an application, then to open up the 'open with' dialog.

I've got the code to do the 'open with' dialog part.

However, if I call Process.Start on a file with an extension not associated
with anything - the file just opens up in notepad. No exception - opens up
with notepad. I'd actually prefer the exception so I know I need to launch
the 'open with' dialog instead.

How do I tell that the file is not associated with an app? And why is the
file being opened with notepad from Process.Start? If I double click on it
in file explorer I get the 'open with' dialog - but Process.Start opens up
notepad, makes no sense to me.

Thanks,
Marina
 
H

Herfried K. Wagner [MVP]

Marina Levit said:
I'd like to open up a file programmatically, but if it is not associated
with an application, then to open up the 'open with' dialog.

I've got the code to do the 'open with' dialog part.

However, if I call Process.Start on a file with an extension not
associated with anything - the file just opens up in notepad.

Which version of Windows are you using? What happens if you open the file
in Windows explorer?

Maybe you can utilize the 'ErrorDialog' property of 'ProcessStartInfo'. If
this property is set to 'True', the "Open with..." dialog should be shown if
the file type is not associated with an application.
 
M

Marina Levit

I have XP Pro.

If I do it in windows explorer I get the 'open with' prompt (as I should).
That's the confusing part.

I tried setting ErrorDialog=True, didn't change anything. There doesn't
appear to be an error as far as Process.Start is concerned, as the file is
just opened in notepad.
 
M

Marina Levit

Oh, and the same thing happens if I open up a command line window and type
in the name of the file. It opens up notepad. Double clicking in windows
explorer brings up the dialog.

If I set UseShellExecute=False, then it can never open up the file with the
default registered application since I am not supplying an EXE path, which
is what it needs.

This is kind of a pain. Seems like it shouldn't be difficult to get this
going.
 
M

Marina Levit

Ok, final update. Turns out there is a registry setting that can be added
that will tell anything being run through the shell to open unknown file
types with notepad. Once I got rid of it, it all worked as expected. No idea
how the registry setting got added - either by accident, or when IT build my
machine.

Anyhow, I get my exception as expected now for unknown file types and can
prompt the user with the 'open with' dialog.

Thanks!
 
K

kimiraikkonen

Ok, final update. Turns out there is a registry setting that can be added
that will tell anything being run through the shell to open unknown file
types with notepad. Once I got rid of it, it all worked as expected. No idea
how the registry setting got added - either by accident, or when IT build my
machine.

Anyhow, I get my exception as expected now for unknown file types and can
prompt the user with the 'open with' dialog.

Thanks!

Which version of Windows are you using? What happens if you open the file
in Windows explorer?
Maybe you can utilize the 'ErrorDialog' property of 'ProcessStartInfo'.
If this property is set to 'True', the "Open with..." dialog should be
shown if the file type is not associated with an application.

If you try to open a file without extension you get an exception that
says kind of: "no app is associated with this app to open"...

eg:

System.Diagnostics.Process.Start("c:\code2")

where actually "code2" is a text file "code2.txt" but i removed the
extension to reproduce the behaviour.
 
M

Marina Levit

It doesn't if you have that registry setting.

Which was very annoying to have to find and remove.

kimiraikkonen said:
Ok, final update. Turns out there is a registry setting that can be added
that will tell anything being run through the shell to open unknown file
types with notepad. Once I got rid of it, it all worked as expected. No
idea
how the registry setting got added - either by accident, or when IT build
my
machine.

Anyhow, I get my exception as expected now for unknown file types and can
prompt the user with the 'open with' dialog.

Thanks!

I'd like to open up a file programmatically, but if it is not
associated
with an application, then to open up the 'open with' dialog.
I've got the code to do the 'open with' dialog part.
However, if I call Process.Start on a file with an extension not
associated with anything - the file just opens up in notepad.
Which version of Windows are you using? What happens if you open the
file
in Windows explorer?
Maybe you can utilize the 'ErrorDialog' property of 'ProcessStartInfo'.
If this property is set to 'True', the "Open with..." dialog should be
shown if the file type is not associated with an application.

If you try to open a file without extension you get an exception that
says kind of: "no app is associated with this app to open"...

eg:

System.Diagnostics.Process.Start("c:\code2")

where actually "code2" is a text file "code2.txt" but i removed the
extension to reproduce the behaviour.
 

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