What are you trying to do?
You create a TextBox - which you never display - set its Text property from a different textbox, create two labels you never display, and then hide everything to be on the safe side...
Try this:
private void buttonclick(object sender,EventArgs e)
{
string currentEntry = string.Format("{0}|{1}|{2}",
++counter,
textBox.Text.Replace("|", "~"),
"hello");
File.AppendAllText("savedpass.txt", currentEntry);
this.Hide();
}
As for your "What I have tried" code, of course you get a "file in use" error - you are probably using the file! Either there is a mistype in the file names and you actually have "savedpass.txt" in both places, or your ReplaceInFile method is not releasing the file properly.
using (StreamReader sr = new StreamReader("savedpass.txt"))
{
string line = "";
while ((line = sr.ReadLine()) != null)
{
string[] lineData = line.Split('|');
string num = lineData[1];
ReplaceInFile("savepass.txt",textbox.text,num);
}
sr.Close();
}