leontager Posted August 10, 2003 Posted August 10, 2003 hi, I am trying to write a file in a loop. Each time it should write seomthing differnet. Instead of rewriting the file, my program adds the new information ot hte file. how can I make it rewrite. my code: Dim writer As New IO.StreamWriter("C:\my folder\ad.html") For i = 1 To 5 ........ reget(uName) jLinks = String.Join("','", v_link, 0, v_rem) writer.Write(jLinks) writer.Flush() next now jLinks changes each time but it is being added at the end of the file while I need it to replace the whole file. I thought about erasing it so that It would create a new one each time but I get a sharing violation. I am pretty sure this is simple to do, just not sure how:p Quote
*Experts* mutant Posted August 10, 2003 *Experts* Posted August 10, 2003 Another overload of the StreamWriter constructor asks whether you wish to append to the file, just specify it to False. It will overwrite the file. Dim writer As New IO.StreamWriter("file path", False) Quote
leontager Posted August 10, 2003 Author Posted August 10, 2003 wow..you just know everything, don't you:D thank you very much. Quote
leontager Posted August 10, 2003 Author Posted August 10, 2003 (edited) rrrr....it still doesn't overwrite the file..I don't understand. Dim writer As New IO.StreamWriter("C:\my folder\ad.html", False) Dim stream As IO.StreamReader Dim wc As New Net.WebClient() Dim i As Integer Dim m As Integer stream = New IO.StreamReader(wc.OpenRead("C:\my folder\file.htm")) For i = 1 To 5 reget(uName) jLinks = String.Join("','", v_link, 0, v_rem) writer.Write( jLinks _ & "'];" & stream.ReadToEnd) writer.Flush() pr(1).Start("IEXPLORE", "C:\my folder\ad.html") Next is there anyway I could delete the file each time? Edited August 10, 2003 by leontager Quote
*Experts* mutant Posted August 10, 2003 *Experts* Posted August 10, 2003 It should work, it should empty the file right during the constructor. Are you sure you are checking the right file or things like that? To delete a file use the IO.File class: IO.File.Delete("path") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.