Hi
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++)
{
sw.WriteLine(listBox1.Items.ToString());
string me = listBox1.Items.ToString();
if (RowCount > 100)
{
listBox2.Items.Add(listBox1.Items[counter].ToString());
counter++;
if (counter == 100)
{
inc++;
sw = new StreamWriter(FileName + inc + ".txt");
//counter = counter - 100;
RowCount = RowCount - counter;
counter = 0;
//FileName = FileName + inc + ".txt";
}
}
else
{
sw.WriteLine(listBox1.Items.ToString());
}
}
sw.Close();
}
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++)
{
sw.WriteLine(listBox1.Items.ToString());
string me = listBox1.Items.ToString();
if (RowCount > 100)
{
listBox2.Items.Add(listBox1.Items[counter].ToString());
counter++;
if (counter == 100)
{
inc++;
sw = new StreamWriter(FileName + inc + ".txt");
//counter = counter - 100;
RowCount = RowCount - counter;
counter = 0;
//FileName = FileName + inc + ".txt";
}
}
else
{
sw.WriteLine(listBox1.Items.ToString());
}
}
sw.Close();
}