Stroppy Porgram

S

SteMc

Help!

One day I'm writing a program and it's working wonderully, co-operating
nicely. The next day I change nothing but it throws up a file i/o error
and I can't work out why :(

I have a streamreader and a streamwriter. The reader is set to the
current html file in a borowser window and the writer is a file called
"temp.txt". I close them and then change them round so the reader is
the temp file and the writer the html file. The reader works fine but
the writer claims the file is in use, despite me having just closed it.
The essential bits of the code are as follows

<code>
Dim reading_file As StreamReader = New
StreamReader(central_file_location + "html files\" + _
AxWebBrowser1.LocationName + ".html") {this opens a file called
"0.html"}
Dim writing_file As StreamWriter = New
StreamWriter(central_file_location + "html files\" + _ "temp.txt")

reading_file.Close()
writing_file.Close()

reading_file = New StreamReader(central_file_location + "html files\" +
"temp.txt")
writing_file = New StreamWriter(central_file_location + "html files\" +
_ AxWebBrowser1.LocationName + ".html") {0.html}
<code end>

the error message I get is...
<error message>
An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll

Additional information: The process cannot access the file
"C:\Documents and Settings\Ste\My Documents\Steve\Ongoing Projects\New
Expert System\html files\0.html" because it is being used by another
process.
<error message end>

Why would this happen? Surely by closing the file it should be free to
open again? I've tried using the object window to see if the reader is
still asigned to the file in question but it gives me info that doesn't
help.

The closing of the file isn't in a loop, after stepping through the
code the closing of the file has definately occured :(

anyhelp is appreciated,

Steve
 
S

Steven Nagy

What about your writer? Does it have the file open as well?

Also, perhaps your permissions in the suggested folder are bogus.
Try something more general and see if it still bugs out.

Steven Nagy
 
S

SteMc

Fixed it. I think maybe I should put a dunces hat on :(

The sub that the above code is in has been called by another procedure.
In the parent procedure the file in question has been opened and not
closed before calling the new procedure. So the debugger is right when
it says the file is still in use.

What I don't understand now though is why in the child procedure an
instance of a file can be opened and closed once (despite the file
being open and in sue to start with) but not twice?

Thanks for your help though,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top