I want to retrieve data from notepad and display it randomly on label. The project is about lucky draw system where i need to make the employee id display randomly.
Below are my code:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("C:/ Users / Nor Asyraf Mohd No / Documents / TestFile.txt"))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
string strRead = sr.ReadLine();
Random random = new Random();
Label1.Text = strRead.ToString();
}
}
}
catch (Exception i)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(i.Message);
}
}