Checking for a PDF reader

M

Mark Rae

Hi,

I've been asked to write a WinForms app which will create reports as PDF
documents.

The client has agreed that all desktops (WinXP Pro, 32-bit Vista Business)
*will* have Adobe Acrobat Reader installed but, in the interests of
robustness, I want to check for this when the app loads.

Would you recommend checking for the Adobe Acrobat Reader specifically, or
just checking that the .pdf file extension has a valid association?

Any assistance gratefully received.

Mark
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

Personally, I would do neither. I would create an install package which
includes the install for the Adobe Acrobat reader so that you can make the
assumption that it is installed.

If you can't do this for some reason or another, and you are embedding
the reader in your app as an ActiveX control, then you could try and create
an instance of the control, and if it fails, you know it's not installed
(you will have to have an interop assembly as a reference in your app for
this).

If you are using the reader externally, then I would go with checking to
see if the extension is mapped to anything. However, I would consider this
solution to be very brittle, and my last resort. After all, a different app
could be registered to handle the PDF extension.
 
M

Mark Rae

Personally, I would do neither. I would create an install package which
includes the install for the Adobe Acrobat reader so that you can make the
assumption that it is installed.

Hmm - OK...
If you are embedding the reader in your app as an ActiveX control

I'm not doing that...
If you are using the reader externally, then I would go with checking to
see if the extension is mapped to anything. However, I would consider
this solution to be very brittle, and my last resort. After all, a
different app could be registered to handle the PDF extension.

OK.
 
D

David Jackson

If you are using the reader externally, then I would go with checking
to see if the extension is mapped to anything. However, I would consider
this solution to be very brittle, and my last resort. After all, a
different app could be registered to handle the PDF extension.

Hello Nicholas,

I'm interested in this and wanted to find out more about it so I Googled
around a bit and the only methods I could find for this in C# seem to use
unmanaged code via pinvoke e.g.
http://www.pinvoke.net/default.aspx/shlwapi/AssocQueryString.html

I've tried the code from the above page and it certainly works, but can you
please tell me:

1) Is this the "right" way to check for a file association in C#? Is there
something in the Framework which I could use instead?

2) If I deliberately ask for the file assocation of a filetype which I know
doesn't exist e.g. *.zzz, the method returns "shell32.dll". Therefore, would
the correct logic be that if the code returns a string which contains
"shell32.dll" then there is no association for that extension? How reliable
is this?

3) Will there be any problems running this code on Vista i.e. will it need
to be run with elevated privileges or even as administrator?

Thanks

DJ
 

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