Question: I have a website that is required to read data from an external txt file..I had put that file in the App\_data folder and read the data from that file using this code

the txt file contain 3 texts.. which are: kevin123 INFO102lec INFO102k

```
   protected void logInButton_Click(object sender, EventArgs e)
{
    string usernameListString = File.ReadAllText(Server.MapPath("~") + "/App_Data/usernameFile.txt");

    string[] userAray = usernameListString.Split(' ');
    bool usernameExists = false;
    for (int i = 0; i < userAray.Length; i++)
    {
        if (usernameTextBox.Text == userAray[i])
        {
            welcomeLabel.Text = "Welcome" + userAray[i];
        }

        if (usernameTextBox.Text != userAray[i])
        {
            welcomeLabel.Text = "unknown user";
        }

        usernameExists = true;

    }

```

I want to write a `for` loop that goes through each item of `userArray`. At the end of the loop, set `usernameExists` to true only if the username entered in the username text box is present in the array.
I coded something which when I type 1 of those name in the textbox?? it give an welcome label if the name doesn exist?? and vice versa!

IS anything wrong with my code above?

Answer: 
try this

```
protected void logInButton_Click(object sender, EventArgs e)
{
string usernameListString = File.ReadAllText(Server.MapPath("~") 
      + "/App_Data/usernameFile.txt");

string[] userAray = usernameListString.Split(' ');
bool usernameExists = false;
for (int  i = 0; i < userAray.Length; i++)
{
    if (userAray[i]==usernameTextBox.Text)
    {
        welcomeLabel.Text = "Welcome" + userAray[i];
        usernameExists = true;
    }
    else
    {
        welcomeLabel.Text = "unknown user";
    }        
}

```
try: 

```
    bool usernameExists = false;
    for (int  i = 0; i < userAray.Length; i++)
    {
        if (userAray == "kevin123")
        {
          usernameExists =true;
        }
    }

```