- 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
Ramesh PalanivelPosted Mar 13, 2018, 2:21 AM
Sagar Pandurang KapPosted Mar 13, 2018, 2:20 AM