title: Read credentials in text file for program c#?
body: <p>This is my program, and it work correctly if i put username and password :</p>
  
  <pre><code> try
   {
  
       var url = @"https://mail.google.com/mail/feed/atom";
       var User = username;
       var Pasw = password;
       var encoded = TextToBase64(User + ":" + Pasw);
       var myweb = HttpWebRequest.Create(url) as HttpWebRequest;
       myweb.Method = "POST";
       myweb.ContentLength = 0;
       myweb.Headers.Add("Authorization", "Basic " + encoded);
       var response = myweb.GetResponse();
       var stream = response.GetResponseStream();
       textBox1.Text += ("Connection established with" + User + Pasw);
   }
   catch (Exception ex)
   {
       textBox1.Text += ("Error connection. Original error: " + ex.Message);
  </code></pre>
  
  <p>now i want read string of texfile, split them and read username and password like this format:   username:password        .    There is my code at the moment:</p>
  
  <pre><code> Stream myStream = null;
   OpenFileDialog openFileDialog1 = new OpenFileDialog();
  
   openFileDialog1.InitialDirectory = "c:\\";
   openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
   openFileDialog1.FilterIndex = 2;
   openFileDialog1.RestoreDirectory = true;
  
   string file_name = "";
   file_name = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + file_name;
  
   if (openFileDialog1.ShowDialog() == DialogResult.OK)
   {
  
        try
        {        
             if ((myStream = openFileDialog1.OpenFile()) != null)
             {
  
                 using (StringReader reader = new StringReader(file_name))
                 {
                      // Loop over the lines in the string.
                      int count = 0;
                      string line;
                      while ((line = reader.ReadLine()) != null)
                      {
                           string[] data = line.Split(':');
                           string username = data[0].Trim();
                           string password = data[1].Trim();
  
                           count++;
                   /*       Console.WriteLine("Line {0}: {1}", count, line);    */
                 }
                 reader.Close();
             }
         }
    }
    catch (Exception ex)
    {
         MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
    }
  </code></pre>