public partial class _Default : System.Web.UI.Page { private Random random = new Random(); private string testFilePath = @"C:\\TestFile.txt"; private List<string> testFileLines; protected void Page_Load(object sender, EventArgs e) { if (!File.Exists(testFilePath)) { Response.Write($"The file does not exist: {testFilePath}"); } else { try { testFileLines = File.ReadAllLines(testFilePath).ToList(); } catch (Exception ex) { Response.Write($"Could not read file {testFilePath}. Exception details: {ex}"); } } } protected void Button1_Click(object sender, EventArgs e) { if (testFileLines != null && testFileLines.Count > 0) { var randomLine = testFileLines[random.Next(testFileLines.Count)]; Label1.Text = randomLine; testFileLines.Remove(randomLine); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)