Le ReadToEnd() doit effectivement fonctionner si tu as bien des retours chariots dans le fichier. On peut faire plus simple au passage
maTextBox.Text = File.ReadAllText(@"X:\monRep\monfichier.txt");
Sinon le "\n" n'est pas la bonne solution pour le ReadLine(). Il faut utiliser Environment.NewLine à la place je pense.
1 2 3 4 5 6 7 8
| using (StreamReader reader = new StreamReader(@"X:\monRep\monfichier.txt"))
{
string line = null;
while ((line = reader.ReadLine()) != null)
{
maTextBox.Text += line + Environment.NewLine;
}
} |
Ou encore
1 2 3 4
| foreach (string line in File.ReadAllLines(@"X:\monRep\monfichier.txt"))
{
textBox1.Text += line + Environment.NewLine;
} |
Partager