Saving Data to a Text File in VB.Net -
i've functioning streamwriter creates text file , places information need in file, whenever re-run application text file created anew current values replacing old. how ensure previous data saved in text file new data being added on it? appending data file seems obvious route, i'm not sure how incorporate code program.
dim corpid, fname, lname, preconf, confcost string corpid = txtcorpid.text fname = txtfirstname.text lname = txtlastname.text if radnotattending.checked = true preconf = "" else preconf = cmbcourses.selecteditem.tostring end if confcost = decattendcost.tostring("c") dim wr streamwriter wr = new streamwriter("c:\users\anon\documents\sampletextfile.txt") wr.writeline(string.format("{0},{1},{2},{3}, {4}", corpid, fname, lname, preconf, confcost)) wr.flush() wr = nothing
you need overload of streamwriter constructor.
just use wr = new streamwriter("c:\users\anon\documents\sampletextfile.txt", true)
you need this one
example:
using wr new streamwriter("c:\users\anon\documents\sampletextfile.txt",true) wr.writeline($"{corpid},{fname},{lname},{preconf},{confcost}) end using
with using
, streamwriter
released when done it, when click button again, no streamwriter
accessing file , can create insatnce of streamwriter
without problems.
Comments
Post a Comment