meng

meng

  • NA
  • 24
  • 19.8k

how to use streamwriter/streamreader?

Sep 28 2012 4:02 PM

i'm try to use streamwriter to save the data from a listbox (in C#) to a text file, but my code is saving the ojectcollection instead of the data from the listbox.

a) data saved to text file is "System.Windows.Forms.ListBox+ObjectCollection"

b)
FileStream dFile = new FileStream("C:\\temp\\data.txt", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(dFile)
//write data to file
sw.WriteLine("{0}", listBox1.Items);
sw.Close();

 

C) please advise how to load data from the saved text file to a lisbox?



 

thanks


Answers (3)