我正在尝试使用以下代码将子项附加到XML文件
string controlFolderPath = string.Empty;
var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (currentPath.Contains("\\bin\\Debug"))
currentPath = currentPath.Replace("\\bin\\Debug", "");
else if (currentPath.Contains("\\bin\\Release"))
currentPath = currentPath.Replace("\\bin\\Release", "");
string strFilename = currentPath + "\\InitialSetup\\ClientList.xml";
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strFilename);
var node = xDoc.DocumentElement.SelectSingleNode("./Client[@Name='" + clientName.Trim() + "']");
if (node != null)
{
MessageBox.Show("The entered Client Name already exists.");
return false;
}
XmlElement clientElement = xDoc.CreateElement("Client");
clientElement.SetAttribute("Name", clientName.Trim());
xDoc.DocumentElement.AppendChild(clientElement);
xDoc.Save(strFilename);
MessageBox.Show("Client " + clientName.Trim() + " added in system");
但是我一直收到错误声明"进程无法访问文件,因为它被其他进程使用"
有人可以帮我解决错误吗?