2 Replies - 163 Views - Last Post: 05 February 2012 - 12:00 PM Rate Topic: -----

Topic Sponsor:

#1 sangwa125  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-February 12

.net save data on a textfile without erasing the old ones with listbox

Posted 05 February 2012 - 11:53 AM

this saves but first erases the old text.
my code is like this:
dim wrt as new io.stremwriter ("C:\myfile.txt")
dim looper as integer
for looper =0 to lstbox1.items.count-1
wrt.writeline(listbox1.items.item(looper))
next
w.close()
end sub

This post has been edited by smohd: 05 February 2012 - 11:57 AM
Reason for edit:: Code tags added. Please use [code] tags when posting codes

Is This A Good Question/Topic? 0
  • +

Replies To: .net save data on a textfile without erasing the old ones with listbox

#2 nK0de  Icon User is offline

  • can't spell BITCH without IT
  • member icon

Reputation: 183
  • View blog
  • Posts: 732
  • Joined: 21-December 11

Re: .net save data on a textfile without erasing the old ones with listbox

Posted 05 February 2012 - 11:57 AM

set the second constructor parameter value as True. It will append the new data to the exisiting data. like this,

Dim wrt As New StreamWriter("C:\myfile.txt", True)


when it is just

Dim wrt As New StreamWriter("C:\myfile.txt")


or

Dim wrt As New StreamWriter("C:\myfile.txt", False)


it will just overwrite the file (if it exists) or create a new file.

and please use code tags when you're posting code.

This post has been edited by nK0de: 05 February 2012 - 12:03 PM

Was This Post Helpful? 0
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: .net save data on a textfile without erasing the old ones with listbox

Posted 05 February 2012 - 12:00 PM

You can set the append flag to true so to append text to the end of the file:
Dim wrt As New IO.StreamWriter("C:\myfile.txt", True)

Also it is StreamWriter not stremwriter.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1