问题
I have a webbrowser control in my winforms application to display a selected pdf file, after this i want to move the pdf file to an other location.
When i trie to move the pdf file it is giving me an error that the file is in use. I tried to make the webbrowser navigate to a other page before it is moved but it still give me this error that the file is used by an other process.
How can i release this pdf file so i can just move it? Disposing the webbrowser didn't do the trick.
回答1:
They say "Adobe Acrobat and Adobe Reader are designed to continue running for a few minutes after you close the browser window in which you viewed PDF files."
The workaround for this seems to be :
Copy the PDF to a temporary file and display it, and then when you navigate away, it doesn't matter if AcroRD32.exe holds onto the PDF for a few minutes because you can still do what you need with the original!
回答2:
The following code releases for me the pdf file, which was displayed in WebBrowser, so I can move it:
webBrowser.Navigate("about:blank")
Also see: How can i delete the file that has been navigated in a webbrowser control?
回答3:
I have had a similiar problem, which was that the form with opened pdf file in browser was hidden and then a new instance of the form was opened, which triggered the same file locked error. For me Disposing of the WebBrowser control just before hiding the form helped.
来源:https://stackoverflow.com/questions/9669698/releasing-displayed-pdf-files-in-webbrowser-control