Results 1 to 4 of 4

Thread: [2005] Listbox Items To Text File Problem

  1. #1

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    [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:
    1. TextWriter tw = new StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + "listfile.txt");
    2. foreach (ListItem item in lstWords.Items)
    3.             {                
    4.                     tw.WriteLine(item.Value);              
    5.             }

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  3. #3

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Re: [2005] Listbox Items To Text File Problem

    I made the file, ran the program and it was empty when I check it.

  4. #4

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Re: [2005] Listbox Items To Text File Problem

    I get an error on: ListItem now that I am retrying this.
    Error 3 The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width