Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically check file that a file association exists before attempting to Process.Start() it?

My .Net Windows Forms application generates a PDF report, which I want to show to the user.

Instead of just assuming the client PC has a PDF viewer installed and blindly throwing the PDF at the Operating System to open, is there a way to check against the list of file associations on the client beforehand, then show a "you need a PDF viewer application installed - here's a couple of suggestions.." dialog if PDF isn't a registered type?

I've found a lot of questions and answers about changing or registering file associations, but I just want an easy way to query the list, not change it.

I'd like a solution that works on Windows XP onwards (WinXP, Vista, Win7).

Thanks for your help

like image 781
Andrew Avatar asked May 22 '11 09:05

Andrew


People also ask

How do you know if a file is being used by another process C#?

First check if the file exists (File. Exists) if so try to open for write within try and catch block, if exception is generated then it is used by another process.


1 Answers

It's better not use the registry directly but rely on the Windows API instead. Here is a link on SO that gives a .NET solution: How do I get File Type Information based on extension? (not MIME) in c#

like image 142
Simon Mourier Avatar answered Oct 19 '22 16:10

Simon Mourier