Home All Groups Group Topic Archive Search About
Author
5 Apr 2005 5:49 AM
George
the following code


        file.delete(filedetails)
            Dim FileStream As StreamWriter = New StreamWriter(filedetails)


produces this error

        The process cannot access the file "D:\data.txt" because it is being
used by another process.


Single user XP sp2 pro environment.

I have tried to sleep the process without success, any ideas would be
appreciated.

Author
5 Apr 2005 6:41 AM
Cor Ligthert
George,

>
>        file.delete(filedetails)
>            Dim FileStream As StreamWriter = New StreamWriter(filedetails)
>
>
Which one creates the error, I assume the first, because I assume that it is
still reading that one. (An  often made mistake). I create it in that case
forever it more like this.

sr.close 'streamreader close
file.move(filedetails, mytempfile) 'renaming and saving
Dim FileStream As StreamWriter = New StreamWriter(filedetails)
and when it is ready
file.delete(mytempfile)

I hope this helps,

Cor
Author
5 Apr 2005 7:28 AM
George
Tried the example below, but still receive the same error message after the
"move"

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23aFScqaOFHA.2532@TK2MSFTNGP09.phx.gbl...
> George,
>
>>
>>        file.delete(filedetails)
>>            Dim FileStream As StreamWriter = New StreamWriter(filedetails)
>>
>>
> Which one creates the error, I assume the first, because I assume that it
> is still reading that one. (An  often made mistake). I create it in that
> case forever it more like this.
>
> sr.close 'streamreader close
> file.move(filedetails, mytempfile) 'renaming and saving
> Dim FileStream As StreamWriter = New StreamWriter(filedetails)
> and when it is ready
> file.delete(mytempfile)
>
> I hope this helps,
>
> Cor
>
Author
5 Apr 2005 7:37 AM
Cor Ligthert
George,

On what line you get the error while debugging?
This can be on every line you know.


Cor