First remove the \n which most likely the issue
Second use Path.Combine
Other than the above, make sure another program does not have the file open.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to add a new line to a txt file by following program, problem is, that the ex.Message says that the file is already in use. Could this be because of the selection in the comboBox?
If so how can i change it.
Thanks :)
try
{
string[] files = Directory.GetFiles(@"C:\ProgramData\timerecording TechSupport\Items");
foreach (string f in files)
{
var fileItem = new FileItem { Title = Path.GetFileName(f), Path = Path.GetFullPath(f) };
comboBox6.Items.Add(fileItem);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void button10_Click(object sender, EventArgs e)
{
try
{
System.IO.File.AppendAllText(mainpath+"\\Items\\" + comboBox6.Text, "\n" + textBox7.Text);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
First remove the \n which most likely the issue
Second use Path.Combine
Other than the above, make sure another program does not have the file open.
.Message says that the file is already in use
As the message says, to write to a text file you need exclusive access to. Other processes must close the file.