I'm trying to write a ip and port to a text file from user input. However the code below only saves part of the created string.
The code I use to write:
private void Edit_Config(string data)
{
if (File.Exists(file_loc))
{
using (StreamWriter edFile = new StreamWriter(file_loc, false))
{
edFile.WriteLine(data);
}
}
else
{
//File not found, creates new config with new data.
using (FileStream fs = File.Create(file_loc))
{
Byte[] bytes = new UTF8Encoding(true).GetBytes(data);
fs.Write(bytes, 0, bytes.Length);
}
}
}
The code I use to call the command
Edit_Config(txt_serverIP.Text + ":" + txt_port.Text);
What I get in return for example if I put '192.168.2.60:8080' I get '192.168.2.6' saved.
edFile.Close();
Closing the file fixed the issue.