- public partial class _Default : System.Web.UI.Page
- {
- private Random random = new Random();
- private string testFilePath = @"C:\Users\Nor Asyraf Mohd No\Documents\TestFile.txt";
- private List
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);
- }
- }
- }
Loading

Sagar Pandurang KapRank #606 · 4K reputationPosted Mar 12, 2018, 10:20 PM EDT
Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 12, 2018, 10:21 PM EDT