Monday, 29 September 2014

XML being used by another process



As soon as I call this method the program breaks and returns an error saying "Cannot access file because it is being used by another process.".


I'm not using this anywhere else in the project or on my computer, why is this happening?



public static void addUser(string newName, string newId)
{
xmldoc.Load("C:\\Users\\AlastairWilkins\\Documents\\Projects\\Employment\\Employment\\employees.xml");

XmlNode employee = xmldoc.CreateElement("employee");
XmlAttribute name = xmldoc.CreateAttribute("name");
XmlAttribute id = xmldoc.CreateAttribute("id");

name.InnerText = newName;
id.InnerText = newId;

employee.Attributes.Append(name);
employee.Attributes.Append(id);

xmldoc.DocumentElement.AppendChild(employee);

xmldoc.Save("C:\\Users\\AlastairWilkins\\Documents\\Projects\\Employment\\Employment\\employees.xml");

}

No comments:

Post a Comment