The code below read a text file with a header of a path and followed by a list of file names.
the code adds each file (from the second line and on) to a ListView.
For some reason the last two lines are never reached.
Any ideas?
private void loadFromFile()
{
if ((faxInOn != null) && File.Exists(@"D:\Settings.ye"))
{
string[] s;
StreamReader sr = new StreamReader(@"D:\Settings.ye", Encoding.Default);
s = sr.ReadToEnd().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
faxInOn.changePath(s[0]);
foreach (string temp in s)
foreach (ListViewItem lvi in listView1.Items)
if (lvi.Text == temp.Substring(1))
lvi.ImageIndex = int.Parse(temp.Substring(0, 1));
sr.Close();
sr.Dispose();
}
}
Thanks
Try using File.ReadLines
For example: