1

I'm writing a document view and I'd like to use the capabilities of the WebBrowser control for some file formats (pdf, e-mail).

Now I have the problem, that for every file format that is unknown to the WebBrowser control, it offers to download the file.

So the question is: How to find out what file formats (file extensions) can be displayed by the browser, so that I can display a message to the user that the current fileformat is not supported for displaying instead of getting a "Do you want to download" dialog box.

bebo
  • 819
  • 1
  • 9
  • 26

1 Answers1

0

If I was you I wouldn't use a WebBrowser control for following reasons:

  • WebBrowser is just a wrapper around IE engine. It uses old version of IE by default, so it can have troubles displaying correctly HTML documents with basic CSS styling. It can be forced to use newer versions of IE or even other engines, but it takes some effort.

  • WebBrowser control purpose is to display and navigate throught web pages. And navigating is essentially downloading. I believe it's gonna be hard if not impossible to prevent WebBrowser from downloading files. I believe one way you can do it is by modifying html files like this: Remove hyperlink but keep text? Also you would probably want to prevent context menu from openning.

  • WebBrowser control is capable of displaying PDF as described here Displaying a PDF in a WPF Application Not Working - WebBrowser or Adobe Control But I have no idea how would you prevent following the links placed in pdf

Instead of using WebBrowser I suggest you to use one of many royalty-free PDF viewing controls and convert your html documents to PDF. I believe suggested approach will take you less time and will be more robust

Community
  • 1
  • 1
netaholic
  • 1,345
  • 10
  • 22
  • I don' think that there are so many free PDF viewer. If you skip all the GPL, AGPL stuff it's not so much. By the way, using the WebBrowser control for PDF works fine with Acrobat Reader. The idea was to use it for other file formats as well, like eml, txt,... It's not a problem to filter for these extentions before passing the files to the WebBrowser control. But how do I know what file formats can be viewed by the WebBrowser control. In WinForms I used the Adobe Reader control. It gave me a little more control about viewing the document, but the Brwoser plugin is sufficiant. – bebo Sep 10 '15 at 16:51