I want to update a file. I opened the file and then tried to write the content to it but got the exception:
The process cannot access the file because it is being used by another process.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("../../../connString.xml", settings);
writer.WriteStartDocument();
writer.WriteComment("This file is generated by the program.");
writer.WriteStartElement("ConnectionString");
if (ConnType == "SQL Server") {
writer.WriteAttributeString("ID", "SQL Server");
writer.WriteAttributeString("DataSource", Convert.ToString(TEServer.EditValue));
writer.WriteAttributeString("Database", Convert.ToString(TEDatabase.EditValue));
writer.WriteAttributeString("UserID", Convert.ToString(TEUserID.EditValue));
writer.WriteAttributeString("Password", Convert.ToString(TEPassword.EditValue));
} else if (ConnType == "Access") {
writer.WriteAttributeString("ID", "Access");
writer.WriteAttributeString("DbLocation", Convert.ToString(BtnEditDBLoc.EditValue));
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
I've been looking at some sources said to be close "XmlWriter" but in my coding i have closed, with : writer.Close();
But still occurs the same error.
Is there anything that can help me, please?
Thanks.