Work arround as Richard MacCutchan suggested: I have used 1 button to get the file and 1 button to save the changes.
public partial class frmEditXML : Form
{
string[] path = Directory.GetFiles(@"C:\Users\decraiec\Documents\Atrias_Automated", "*.XML");
public frmEditXML()
{
InitializeComponent();
}
private void btnEditfile_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
richTextBox1.Text = openFileDialog1.FileName;
File.ReadAllText(richTextBox1.Text);
}
openFileDialog1.Filter = "xml files|*.xml|All files|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
}
catch (Exception exc)
{
MessageBox.Show("An error occured: " + System.Environment.NewLine + exc.ToString() + System.Environment.NewLine);
throw;
}
}
}
private void frmOpenRead_Load(object sender, EventArgs e)
{
Application.Exit();
}
private void btnSavechanges_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
File.WriteAllText(saveFileDialog1.FileName, richTextBox1.Text);
}
}
}