[2005] Listbox Items To Text File Problem
Hello, I am trying to save all of the items in a listbox to a file so I used the following code:
csharp Code:
TextWriter tw = new StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + "listfile.txt");
foreach (ListItem item in lstWords.Items)
{
tw.WriteLine(item.Value);
}
That does not work, I don't know what to use for ListItem in the foreach. I tried doing a loop at first, and had no luck, so I searched around on google for a while and got the above code, but I changed it a little for what I needed and It doesn't work. I am used Visual Basic where you just do a simple loop. How do I do this?
Thanks
Re: [2005] Listbox Items To Text File Problem
Perhaps you could explain "could not work". Is it just empty strings or do you get an error?
Re: [2005] Listbox Items To Text File Problem
I made the file, ran the program and it was empty when I check it.
Re: [2005] Listbox Items To Text File Problem
I get an error on: ListItem now that I am retrying this.
Quote:
Error 3 The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)