-1

How do I insert lines of a external text file into the domainupdown items in visual c#? each line of text must correspond to a single items.

domainUpDown.Items.Add(line1);
domainUpDown.Items.Add(line2);
domainUpDown.Items.Add(lines n);

ecc

  • What doesn't work with your code? Are you really asking how to retrieve all lines of a text file? – Tim Schmelter Aug 30 '18 at 16:11
  • No problem. But you could have searched this. There are plenty of [duplicates](https://stackoverflow.com/questions/8037070/whats-the-fastest-way-to-read-a-text-file-line-by-line) and [MSDN](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-a-text-file-one-line-at-a-time) also helps. – Tim Schmelter Aug 30 '18 at 16:32
  • Possible duplicate of [What's the fastest way to read a text file line-by-line?](https://stackoverflow.com/questions/8037070/whats-the-fastest-way-to-read-a-text-file-line-by-line) – Micheal O'Dwyer Aug 30 '18 at 17:39

1 Answers1

1

Adapted from: https://www.dotnetperls.com/file-readalllines

string[] lines = File.ReadAllLines("C:\\rearrange.txt");
foreach(var line in lines)
{
   domainUpDown.Items.Add(line);
}
Neil
  • 11,059
  • 3
  • 31
  • 56