C# Taking a listbox with many values, and dividing it up into mulitple text files -


i having hardest time figuring out how this.

i have listbox lot of data in it. want take listbox , have button save it.

the button choose directory put files in. afterwards, program should start saving these values text file naming schema seed1.txt, seed2.txt, etc.

the thing is, put 100 items each text file generated until list done.

for saving path have:

        stream s;         string folderpath = string.empty;          using (folderbrowserdialog fdb = new folderbrowserdialog())         {             if (fdb.showdialog() == dialogresult.ok)             {                 folderpath = fdb.selectedpath;                 messagebox.show(folderpath);              } 

for saving in 1 shot, believe work:

         int total = list_failed.items.count;            (int = 0; < list_failed.items.count; i++)             {                  streamwriter text = new streamwriter(s);                 text.write(list_failed.items[i]);                 s.close(); 

i'm not sure rest though. filenames perhaps

          string filename;             int = 0;                         {                 filename = "seed" + ++i + ".txt";             } while (files.contains(filename)); 

here's working example can use.

        string pathname = server.mappath("/");         int counter = 1;         string file = string.empty;          list<string> list = new list<string>();           //add list items         (int = 0; <= 1234; i++)         {             list.add(string.format("item {0}", i));         }           //write file         (int = 1; < list.count(); i++)         {             //generate dynamic filename path             file = string.format("{0}seed{1}.txt", pathname, counter);              //the using statement closes streamwriter when completes process             using (streamwriter text = new streamwriter(file, true))             {                 //write line                 text.write(list[i]);             }              //check see if max lines have been written             if (i == counter * 100) counter++;                         } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -