|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
FileIOException when trying to delete a file in a while loopand if it does, it will delete the file and create a new file with the same name. The first time it works perfect, but the second time it gives me a FileIOException. I want to prevent this from happening. What can i do to make sure the file isn't in use anymore the second time i try to delete it? for each dr in table.rows if file.exist("C:\sample.txt") then file.delete("C:\sample.txt") dim sw as new streamwriter("C:\sample.txt") sw.writeline(MyString) sw.close else dim sw as new streamwriter("C:\sample.txt") sw.writeline(MyString) sw.close end if -- Huahe "Huahe" <Hu***@discussions.microsoft.com>'s wild thoughts were released on Tue, 24 May 2005 05:15:15 -0700 bearing thefollowing fruit: Show quoteHide quote >I try to delete a file in a for each loop. My code checks if the file exists If that's dot net code then you need to be in a 'dotnet'>and if it does, it will delete the file and create a new file with the same >name. >The first time it works perfect, but the second time it gives me a >FileIOException. I want to prevent this from happening. What can i do to make >sure the file isn't in use anymore the second time i try to delete it? > >for each dr in table.rows > if file.exist("C:\sample.txt") then > file.delete("C:\sample.txt") > dim sw as new streamwriter("C:\sample.txt") > sw.writeline(MyString) > sw.close >else > dim sw as new streamwriter("C:\sample.txt") > sw.writeline(MyString) > sw.close >end if group. Jan Hyde (VB MVP) -- How many calfs did the mother cow have? About heifer dozen. (James D. Ertner) [Abolish the TV Licence - http://www.tvlicensing.biz/] |
|||||||||||||||||||||||