I'm trying to write xml file starting from JSON data using c#. I see this strange issue: file is removed as soon as created. If I debug the code, I see that file is alive until the using closing statement, after this line, file will be deleted.
Could anyone help me?
Below there is my code:
string path = "c:\\temp\\";
// Write JSON to XML file
string json = "{\"WorkOrderId\":\"WOAA_002_FQjjjjjjjj\",\"WorkOrderName\":\"OP_AAA001\",\"InternalKey\":\"WOAA_002_FQ@iKey@OP_AAA001\",\"parameterDataList\":[{\"Description\":\"Valore PR\",\"InspectionType\":\"Numeric\",\"Value\":\"\",\"LowerLimit\":null,\"NominalValue\":null,\"UpperLimit\":null,\"UoM\":\"n/a\",\"Skill\":true,\"Sequence\":\"1\",\"ParameterValueALTDatetime\":\"\"},{\"Description\":\"Valore PR\",\"InspectionType\":\"String\",\"Value\":\"test\",\"LowerLimit\":null,\"NominalValue\":null,\"UpperLimit\":null,\"UoM\":\"n/a\",\"Skill\":true,\"Sequence\":\"2\",\"ParameterValueALTDatetime\":\"\"}]}";
XmlDocument uiXmlDoc = JsonConvert.DeserializeXmlNode(json, "root");
// Get data for compose filename
string woId = "WOAA_PAOLO";
string operation = "OP_AAA001";
string dcId = "TK-18-0000000332";
if (!path.EndsWith("\\")) path += "\\";
//Compose filename
string fileName = path + woId + "@" + operation + "@" + dcId + ".xml";
//Save the xml and then cleanup
XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
using (StreamWriter outStream = new StreamWriter(@fileName))
{
XmlWriter writer = XmlWriter.Create(outStream, settings);
uiXmlDoc.Save(writer);
}