I have a C# app that reads all the files in a folder, storing them into an array. Then the app writes the array to a text file.
I want to display the name of the file in a label. Here is what I have tried, but my app freezes and it displays only the name of the last file.
private void button1_Click(object sender, EventArgs e)
{
ListAllFiles(@"C:\mmc2", ref label1);
}
private void ListAllFiles(string path, ref Label lbl)
{
string savePath = @"C:\Users\Diza\Desktop\AllFiles.txt";
string[] files = Directory.GetFiles(path,"*.*", SearchOption.AllDirectories);
StreamWriter myWriter = new StreamWriter(savePath);
int count=0;
DateTime dtStart = DateTime.Now;
myWriter.WriteLine("Start: " + dtStart.ToShortTimeString());
foreach (string val in files)
{
lbl.Text = val;
myWriter.WriteLine(val);
count++;
}
}