tags:

views:

93

answers:

5

I have a program that is supposed to save reports in different file formats, and if there is an application associated with the file extension, then open that file using that application.

Is is possible to get all file extensions that have applications associated with them in windows?

I tried the registry entry HK_CLASSES_ROOT{extension}, but i looked at a base windows xp ( without office), and it still has keys for all kinds of extensions..

+1  A: 

You don't have to get the associated application. You can simply use

System.Diagnostics.Process.Start("fileName.xyz");

to open a file with the associated application.

0xA3
A: 

I would need to know if there is any associattion before attempting to open the file, also if the association doesnt exist, then i need to open the folder in windows explorer where the file resides ...

This is a comment, not an answer. Either leave a comment or edit your question.
Geoffrey Chetwood
A: 

Take a peek at the ASSOC command on the command-line. It may give you the information that you need. (Try 'assoc /?', or just run 'assoc' in a shell.)

dash-tom-bang
A: 

I tried running the assoc command using the following code ..

System.Diagnostics.Process proc = System.Diagnostics.Process.Start("/C calc"); proc.OutputDataReceived +=new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived); proc.WaitForExit();

but keep getting file not found exception ...

Your code fails because "/C calc" is probably a non existing file on your machine. What should the code do?
0xA3
+1  A: 

I've used this in the past: http://www.codeproject.com/KB/dotnet/System_File_Association.aspx

D. Patrick