using System using SystemCollectionsGeneric using SystemComp
using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.IO;
 namespace WindowsFormsApplication8
 {
 public partial class Form1 : Form
 {
 public Form1()
 {
 InitializeComponent();
 }
 const int SIZE = 18;
 string[] acct = new string[SIZE];
 private void form1_Load(object sender, EventArgs e)
 {
 try
 {
 StreamReader inputFile;
 inputFile = File.OpenText(\"ChargeAccounts.txt\");
 int index = 0;
 while (index < acct.Length && !inputFile.EndOfStream)
 {
 acct[index] = inputFile.ReadLine();
 index++;
 }
 inputFile.Close();
 }
 catch (Exception ex)
 {
 MessageBox.Show(ex.Message);
 }
 }
 private void CheckButton_Click(object sender, EventArgs e)
 {
 Boolean valid = false;
 for (int i = 0; i < acct.Length; i++)
 {
 if (acct[i] == InputTextbox.Text)
 {
 valid = true;
 break;
 }
 }
 if (valid == true)
 {
 MessageBox.Show(\"It is a Valid Charge Account\");
 }
 else
 MessageBox.Show(\"It is Not a Valid Charge Account\");
 }
 }
 }
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.IO;
 namespace WindowsFormsApplication8
 {
 public partial class Form1 : Form
 {
 public Form1()
 {
 InitializeComponent();
 }
 const int SIZE = 18;
 string[] acct = new string[SIZE];
 private void form1_Load(object sender, EventArgs e)
 {
 try
 {
 StreamReader inputFile;
 inputFile = File.OpenText(\"ChargeAccounts.txt\");
 int index = 0;
 while (index < acct.Length && !inputFile.EndOfStream)
 {
 acct[index] = inputFile.ReadLine();
 index++;
 }
 inputFile.Close();
 }
 catch (Exception ex)
 {
 MessageBox.Show(ex.Message);
 }
 }
 private void CheckButton_Click(object sender, EventArgs e)
 {
 Boolean valid = false;
 for (int i = 0; i < acct.Length; i++)
 {
 if (acct[i] == InputTextbox.Text)
 {
 valid = true;
 break;
 }
 }
 if (valid == true)
 {
 MessageBox.Show(\"It is a Valid Charge Account\");
 }
 else
 MessageBox.Show(\"It is Not a Valid Charge Account\");
 }
 }
 }
 Solution
There are 2 problem in this code:
First:
Form1.Designer.cs
In InitializeComponent() if there is no Form1_Load event then your code wont execute form1 Load event, so add this in InitializeComponent()
this.Load += new System.EventHandler(this.Form1_Load);
In Form1.cs
change private void form1_Load(object sender, EventArgs e) To private void Form1_Load(object sender, EventArgs e)
as you can observe i have changed form1_Load to Form1_Load
Second Problem:
Please mention the file path
if you just entered the file name the program looks for file in debug folder.
so mention the path for example:
inputFile = File.OpenText(@\"P:\\praticedemo\\Examples\\ChargeAccounts.txt\");



