views:

1418

answers:

5

We have a form that hosts the WebBrowser control. That is the only control on the form.

We pass the form the file path of a temporary PDF file and it does:

WebBrowser1.Navigate(Me._PathToPdf)

When the form is closing, it navigates away from the PDF file:

WebBrowser1.Hide()
WebBrowser1.Navigate("about:blank")

Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
    Application.DoEvents()
    System.Threading.Thread.Sleep(50)
Loop

Once the form is closed, the calling class then deletes the temporary PDF file.

This process works great... until we installed Internet Explorer 8. For some reason, the combination of IE8 and Adobe Acrobat 8 (or 9) causes an extra file lock handle to be placed on the temporary PDF file. The extra lock handle does not go away until the entire application is shut down. I should also mention that there are no locks on the file until the file is opened by Acrobat.

We can reproduce this on multiple machines and it is always the combination of IE8 and Adobe Acrobat Reader. We can install Foxit Reader 3 instead of Adobe Acrobat and things work fine. Likewise, we can run the app on a machine with IE7 and Adobe Acrobat, and things work fine. But, when you mix the magic potion of IE 8 and Acrobat, you end up with a mess.

Can anyone tell me why I'm getting an extra file lock that persists until the end of the application?

Thanks.

An example application that demonstrates my problem can be found here: PDFLockProblemDemo.zip

A: 

I can't reproduce this. Do you have a binary, or more information on your host computers?

I've got:

  • IE 8.0.6001.18702
  • Adobe Reader 8.1.4
  • Windows Vista SP1
Mark
There is Adobe Acrobat Reader 9 out - I wonder if that can account for the difference between the OP and you?
Andy
I wondered about that, but "For some reason, the combination of IE8 and Adobe Acrobat 8 (or 9) causes an extra file lock"
Mark
Thank you for the response. I added a code example in the main question. I couldn't figure out how to attach it so, it's a link to another site :(Also, this occurs with both Acrobat 8 and 9, but thanks for the comment, Andy.
Jason Williams
Oh yeah, I forgot to mention that I'm using Windows XP SP3 on all of my test machines. I haven't tried to reproduce this on Vista, yet.
Jason Williams
Ahh yes, that gives the bug. And strangely, so does my test program now...
Mark
A: 

Any progress on this? We are having the exact same problem. Our application has been working fine for years, and we've had some people upgrade to IE8 recently (all XP Pro with Acrobat 8.x), and now they are having this problem.

I am working in a Windows Form app under .NET 2.0, using the WebBrowser control. When the app is done viewing a PDF, I do a Dispose() of the control, and wait for the file to be released so I can delete it, but it never gets released until my app quits.

If anyone has any info, I'd much appreciate it.

Thanks, _Steve

srochenh
Thank you for your comment. I have yet to find a solution.When you get enough rep. up the question. :)I'm very glad we're not the only ones.
Jason Williams
+1  A: 

Still no solution found, but more info: Previously I had tested with XP Pro, Acrobat *.x and .NET 2.0 (built with VS 2005). Since then, I have also tested in a variety of scenarios that include Vista, Acrobat 9.x and .NET 3.5 (built with VS 2008).

Same results though: as long as the browser is IE8, the PDF file doesn't get released when you call Dispose() on the WebBrowser control. It does get released when the app is closed, but that doesn't help us...

Hope this helps, _Steve

Yes, that accurately describes what we're running into, as well.Thanks for the update.
Jason Williams
A: 

We had the same problem with IE8 and Acrobat. In our case we simply needed to be able to overwrite the temporary PDF and redisplay it. We found that we could simply open the PDF, write 0 bytes then close. After that we would open the file and write the new PDF information and then redisplay the temporary file.

In summary, we did not solve the file locking problem, instead we just left the file handle attached and reused the file until the user closed the app.

Hope this helps, Brian.

Brian
+1  A: 

Seems to me the real problems is using a WebBrowser control to host the Adobe Reader web browser plugin to display PDFs. Isn't there a better way to display PDFs directly without introducing a dependency on a web browser? Doesn't Adobe provide an SDK or an ActiveX control you can host directly inside your form?


UPDATE: I looked around and found this post where they access an Adobe ActiveX control (AxAcroPDFLib.AxAcroPDF) and simply call:

axAcroPDF1.LoadFile("mypdf.pdf");
axAcroPDF1.Show();
Lucas
Yes, we have actually resorted to using the COM object provided by Adobe Acrobat. However, this is less than ideal because now are directly tied to Adobe Acrobat and must put that program as a prerequisite to our application. Before, we just required a PDF viewing application (Acrobat or Foxit most of the time).
Jason Williams