I have a code to create an xml file on a server directory,
this code is working like a charm until users process this code at A SAME TIME.
the user who has a milliseconds faster will success generate a file and the other will losing it.
please help me guys.
public static void XmlOrder(arg_order mod, string NewAddress)
{
XmlDocument XDoc = new XmlDocument();
XmlDeclaration xde = XDoc.CreateXmlDeclaration("1.0", "", "");
XDoc.AppendChild(xde);
XmlElement XElemRoot = XDoc.CreateElement("Digital_Order");
XElemRoot.SetAttribute("xmlns", "");
XDoc.AppendChild(XElemRoot);
foreach (arg_order modDetail in mod.arg_orders) {
XmlElement Xsource = XDoc.CreateElement("Document");
XElemRoot.AppendChild(Xsource);
XmlElement XTemp = XDoc.CreateElement("wt_web_Id");
XTemp.InnerText = modDetail.order_detail_id.ToString();
Xsource.AppendChild(XTemp);
XTemp = XDoc.CreateElement("wt_addr");
XTemp.InnerText = modCompany.qad_no;
Xsource.AppendChild(XTemp);
}
//naming and path
string name = arg_order_detail.FindAll().Count.ToString() + ".xml";
string path = ArgenXmlOrderPath + "/" + name;
XDoc.Save(path);
}
That is cause your users are trying to write the same file at the same time.
Make your file names unique by adding something like the orderID to the name of the file.