Release displayed PDF files in web browser control mode

I have a webbrowser control in my winforms application to display the selected PDF file, after which I want to move the PDF file to another location.

When I try to move the pdf file, it gives me an error that the file is being used. I tried to get the webbrowser to go to another page before moving it, but it still gives me this error that the file is being used by another process.

How can I free this pdf file so that I can just move it? Recycling your web browser did not do the trick.

+4
source share
3 answers

They say that "Adobe Acrobat and Adobe Reader are designed to continue working for several minutes after closing the browser window in which you viewed PDF files."

The workaround for this seems to be:
Copy the PDF file to a temporary file and display it, and then when you move it does not matter if AcroRD32.exe is held in PDF for several minutes, because you can still do what you need with the original!

+5
source

The following code releases for me a pdf file that was displayed in WebBrowser, so I can move it:

webBrowser.Navigate("about:blank") 

Also see: How to delete a file that has been moved in a web browser control?

0
source

I had a similar problem, which was that the form with the open PDF file in the browser was hidden, and then a new instance of the form was opened, which caused the same file lock error. Removing the WebBrowser control before hiding the form helped me.

0
source

Source: https://habr.com/ru/post/1401007/


All Articles