title: Append data to existing file in C#
body: <p>i have written the following code to append the data with existing data as it is but my code overwrite this </p>
  
  <p>what should i do the changes to code append data.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      fname = Request.Form["Text1"];
      lname = Request.Form["Text2"];
      ph = Request.Form["Text3"];
      Empcode = Request.Form["Text4"];
  
      string filePath = @"E:Employee.txt";
      if (File.Exists(filePath))
      {
          //StreamWriter SW;
          //SW = File.CreateText(filePath);
          //SW.Write(text);
          //SW.Close();
          FileStream aFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);
          StreamWriter sw = new StreamWriter(aFile);
          sw.WriteLine(Empcode);
          sw.WriteLine(fname);
          sw.WriteLine(lname);
          sw.WriteLine(ph);
          sw.WriteLine("**********************************************************************");
  
          sw.Close();
          aFile.Close();
      }
      else
      {
          //sw.Write(text);
          //sw.Flush();
          //sw.Close();
          //StreamWriter SW;
          //SW = File.AppendText(filePath);
          //SW.WriteLine(text);
          //SW.Close();
  
          FileStream aFile = new FileStream(filePath, FileMode.Append, FileAccess.Write);
          StreamWriter sw = new StreamWriter(aFile);
  
          sw.WriteLine(Empcode);
          sw.WriteLine(fname);
          sw.WriteLine(lname);
          sw.WriteLine(ph);
          sw.WriteLine("**********************************************************************");
  
          sw.Close();
          aFile.Close();
          //System.IO.File.WriteAllText(filePath, text);
      }
      Response.Write("Employee Add Successfully.........");
  }
  </code></pre>