vendredi 18 avril 2014

.net - c# fractionner un fichier texte dans deux listbox différent où premières lignes du fichier texte apparaît dans listbox1 et autres apparaît dans listbox2 - Stack Overflow


I am stucked with displaying a textfile in two different listbox, the textfile contains list of links, and i want that, when someone upload the list, 1st 100 lines of textfile goes to listbox1 and the 2nd 100 lines goes to listbox2.


Any help or suggestion will be highly appreciated


OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Text Files|*.txt";
openFileDialog1.Title = "Select a Text file";
openFileDialog1.FileName = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string file = openFileDialog1.FileName;

string[] text = System.IO.File.ReadAllLines(file);
foreach (string line in text)
{


listBox1.Items.Add(line);


}
listBox2.Items.Add(""); //

}
listBox1.SetSelected(0, true);
listBox2.SetSelected(0, true);



int lineNum = 1;

foreach (string line in System.IO.File.ReadAllLines(myFilePath))
{
if (lineNum <= 100)
{
listBox1.Items.Add(line);
}
else
{
listBox2.Items.Add(line);
}

lineNum++;
}


I am stucked with displaying a textfile in two different listbox, the textfile contains list of links, and i want that, when someone upload the list, 1st 100 lines of textfile goes to listbox1 and the 2nd 100 lines goes to listbox2.


Any help or suggestion will be highly appreciated


OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Text Files|*.txt";
openFileDialog1.Title = "Select a Text file";
openFileDialog1.FileName = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string file = openFileDialog1.FileName;

string[] text = System.IO.File.ReadAllLines(file);
foreach (string line in text)
{


listBox1.Items.Add(line);


}
listBox2.Items.Add(""); //

}
listBox1.SetSelected(0, true);
listBox2.SetSelected(0, true);


int lineNum = 1;

foreach (string line in System.IO.File.ReadAllLines(myFilePath))
{
if (lineNum <= 100)
{
listBox1.Items.Add(line);
}
else
{
listBox2.Items.Add(line);
}

lineNum++;
}

0 commentaires:

Enregistrer un commentaire