Opening files in webbrowser
I have a web browser control which I load with a variety of word docs.
If I do the following :
Code:
webBrowser1.Navigate(Application.StartupPath + "\\" + filename_A);
Then
Code:
webBrowser1.Navigate(Application.StartupPath + "\\" + tempFileNam_B);
System.IO.File.Delete(filename_A);
I always get the error/Exception
"The process cannot access the file because it is being used by another process."
How can I clear this up ? Is there any way to unlock the file after loading a new file ?
Thanks In Advance All
Re: Opening files in webbrowser
vene,
Your issue is that you are trying to delete file A immediately when you navigate to file B, and file A hasn't been closed at that point.
What you need to do, is use the DocumentCompleted event of the browser to be your indicator that the doc has fully loaded. at that point delete file A.
The only problem you may have, is I don't think the "temp" doc files (the ones that hold edits until you save) get deleted when you do what you are doing.
Re: Opening files in webbrowser
Re: Opening files in webbrowser
go up to the top of the thread and on the left you will see a menu item named Thread Tools, just click that and then go to Mark Thread Resolved :)
Re: Opening files in webbrowser
Actually after further testing I have discovered that it doesn't work.
I cannot delete the file because a Microsoft Word process is still running and keeping the files locked.
Bum....this is driving me nuts
Re: Opening files in webbrowser
vene, can you post your code, or at least a sample that does the same thing? I did test, and didn't have problems. Once documentcompleted fires for the SECOND doc you open, the reference to the first doc should be gone, and you should be able to delete the file from the disk.