Releasing displayed pdf files in webbrowser control

北战南征 提交于 2021-02-16 13:13:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!