How can I programmatically check a file that file associations exist before trying to execute Process.Start ()?

My.Net Windows Forms application creates a PDF report that I want to show to the user.

Instead of assuming that the PDF viewer is installed on the client PC and blindly drop the PDF in the operating system to open, there is a way to check the list of file associations on the client in advance , and then show "you need to install the application to view PDF files - here are a few sentences .. "if the PDF is not a registered type?

I found a lot of questions and answers about changing or registering file associations, but I just need an easy way to request a list, not change it.

I need a solution that works in Windows XP and beyond (WinXP, Vista, Win7).

thanks for the help

+7
source share
2 answers

It’s better not to use the registry directly, but instead use the Windows API. Here is a link to SO that provides a .NET solution: How do I get file type information based on extension? (not MIME) in C #

+8
source

I found that there is a .pdf key in the registry, maybe it can help you:

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.pdf] "Content Type"="application/pdf" @="AcroExch.Document" [HKEY_CLASSES_ROOT\.pdf\OpenWithList] @="" [HKEY_CLASSES_ROOT\.pdf\OpenWithList\AcroRd32.exe] @="" [HKEY_CLASSES_ROOT\.pdf\ShellEx] [HKEY_CLASSES_ROOT\.pdf\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}] @="{DC6EFB56-9CFA-464D-8880-44885D7DC193}" 
0
source

All Articles