views:

685

answers:

3

Hi Friends,

I'm using the WebBrowser control inside a Windows Form to display a PDF.

Whenever the PDF is regenerated, however, the WebBrowser control only displays its local cached version and not the updated version from the server.

I'm using the Refresh() method shown below to try and force the control to reload the PDF, but it doesn't work:

_webBrowser.Navigate(pdfUrl);

_webBrowser.Refresh(WebBrowserRefreshOption.Completely)

Do I have to do anything else to force the refresh to reload the PDF from the server?

A: 

Is the PDF being embedded with an object tag or something? If so, asking the browser object to refresh won't have any effect- you have to script the PDF viewer to do the refresh (eg, get ahold of the PDF viewer object by ID from the webbrowser control), since that's what downloaded it.

nitzmahone
+1  A: 

Since WebBrowser (actually IE's Trident engine) use WinInet for networking, you can use WinInet's cache management APIs to remove the cached files before navigating.

Sheng Jiang 蒋晟
+1  A: 

Sheng Jiang is correct - you need the programmatically clear IE's cache. Here is sample code showing how to do this in c#: http://www.gutgames.com/post/Clearing-the-Cache-of-a-WebBrowser-Control.aspx

It is based heavily on the Microsoft KB article here: http://support.microsoft.com/kb/326201

And to pre-empt the question - yes this is a huge pain in the neck, and no, there isn't another way around it. Good luck!

Chris Clark