Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hi i need to separate 1 text fil

Hi i need to separate 1 text fil

Hi i need to separate 1 text fil


i need to separate 1 text file into 100 records in each file, so my logic create those text file, but the data is not complete in each text file, 5 records are missing.

In this code, first i load all records into a listbox, then try to separate them in 100s

private void WriteToFile()
int RowCount = listBox1.Items.Count;
string FileName = "C:\\Users\\bbdnet0986\\Documents\\MyExpotedQADATA";
StreamWriter sw = new StreamWriter(FileName + ".txt");
int inc = 0;
int counter = 0;
//StreamWriter sw = new StreamWriter(FileName+inc + ".txt");
for (int i = 0; i < listBox1.Items.Count; i++)
string me = listBox1.Items[i].ToString();

if (RowCount > 100)

if (counter == 100)

sw = new StreamWriter(FileName + inc + ".txt");

//counter = counter - 100;
RowCount = RowCount - counter;
counter = 0;
//FileName = FileName + inc + ".txt";



RE: Hi i need to separate 1 text fil

homework? okay, try to code this pseudo:


function main()

  let sourceStream = open source file
  let filecounter = 1

  while sourceStream NOT eof
    call copyLines(sourceStream, filecounter)
    increment filecounter

end function

function copyLines(sourceStream, filecounter)
  let linecounter = 1
  let file = "file" + filecounter
  open newbuffer

  while sourceStream NOT eof and linecounter not 100
    let line = read sourceStream
    write to newbuffer
    increment linecounter

end function 
It's not a perfect pseudo but this should give you an idea.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close