4 Replies - 1164 Views - Last Post: 19 April 2014 - 10:20 AM Rate Topic: -----

#1 apopphis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 14

How to save text from listbox to the txt file

Posted 19 April 2014 - 08:48 AM

hi guys,
I have question for you, I tried to save some data from my listbox to the text file, but didn't work... I think I tried many combination for code but still didn't work. Have an idea what to do? I will be gratefull to you...
FileStream fs = new FileStream("tx.txt", FileMode.Create);
StreamWriter sr = new StreamWriter(fs);
sr.Write(listBox1.Text); //there is that problem, but I'm not sure how to write for success
sr.Close();


Is This A Good Question/Topic? 0
  • +

Replies To: How to save text from listbox to the txt file

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,181
  • Joined: 12-June 08

Re: How to save text from listbox to the txt file

Posted 19 April 2014 - 08:52 AM

Didn't work how? Put a break point on that line 3 and see what the selected value/values are.
Was This Post Helpful? 0
  • +
  • -

#3 apopphis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 14

Re: How to save text from listbox to the txt file

Posted 19 April 2014 - 09:39 AM

I want all text form listbox not just selected items...I know, when I have listBox1.Text - that give me only selected items, but I want all and I don't know how to get it
Was This Post Helpful? 0
  • +
  • -

#4 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: How to save text from listbox to the txt file

Posted 19 April 2014 - 10:14 AM

What is the problem, put the breakpoint there and see the output it gives. Also it won't hurt to check the StreamWriter class for reminder
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,181
  • Joined: 12-June 08

Re: How to save text from listbox to the txt file

Posted 19 April 2014 - 10:20 AM

A list box has a collection of 'items'. If you want every single item in the list box to a textfile then use a for loop to go through all the items and use the streamwriter (in the forloop body) to write lines to a textfile.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1