I work in a WPF application, I want to create an XML file and load it simultaneously in a window. At the moment, my code is working fine, but when I want to load the created file in a window, it tells me that the File is being used by another process. Here is my code
var now = DateTime.Now;
var timestamp = "" + now.Hour + now.Minute + now.Second;
string sb = "test";
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
File.WriteAllText(string.Format("{0}\\{1}.xml", path, timestamp), sb);
File.AppendText(string.Format("{0}\\{1}.xml", path, timestamp));
XmlDocument XMLdoc = new XmlDocument();
try
{
XMLdoc.Load(string.Format("{0}\\{1}.biml", path, timestamp));
}
catch (XmlException)
{
MessageBox.Show("The XML file is invalid");
return;
}
vXMLViwer.xmlDocument = XMLdoc;
source
share