Multiple users can not access the file at the same time
This issue is coming in live could you please help me in that to overcome of this?
public void CreateXMLEditTutorfeedback(PlanXmlfeedback YourClassObject)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
XmlSerializer xmlSerializer = new XmlSerializer(YourClassObject.GetType());
using (MemoryStream xmlStream = new MemoryStream())
{
xmlSerializer.Serialize(xmlStream, YourClassObject);
xmlStream.Position = 0;
xmlDoc.Load(xmlStream);
XDocument doc = XDocument.Parse("<Root><Edit>" + xmlDoc.DocumentElement.InnerXml + "</Edit></Root>");
string dirLoc = HttpContext.Current.Server.MapPath("~/TutorFeedBackEdit/") + DateTime.UtcNow.ToShortDateString().Replace('/', '_');
string fileName = "TutorFeedBackEdit.xml";
if (Directory.Exists(dirLoc) == false)
{
Directory.CreateDirectory(dirLoc);
doc.Save(dirLoc + "\\" + fileName);
}
else
{
if (File.Exists(dirLoc + "\\" + fileName))
{
XDocument xDocument = XDocument.Load(dirLoc + "\\" + fileName);
xDocument.Document.Descendants("Edit").LastOrDefault().AddAfterSelf(doc.Elements("Root").Descendants().FirstOrDefault());
xDocument.Save(dirLoc + "\\" + fileName);
}
else
{
doc.Save(dirLoc + "\\" + fileName);
}
}
}
}
catch (Exception ex)
{
objErr.WriteXMLErrorLog(ex, "Common", "TutorFeedBackEdit", "", "");
}
}