2
Answers

File IO exception

Peter

Peter

16y
6.8k
1

Hi.

I have this code:

System.IO.File.Create(productDetailsPath);
XmlDocument xmlDoc = new XmlDocument();
XmlElement details = xmlDoc.CreateElement("ProductDetalils");
details.SetAttribute("Name", ProjectName);
details.SetAttribute(
"Revision", RevisionNumber);
XmlText textNode = xmlDoc.CreateTextNode(textBoxConfigDetails.Text);
details.AppendChild(textNode);
xmlDoc.AppendChild(details);
xmlDoc.Save(productDetailsPath);

when I use the command xmlDoc.Save(productDetailsPath); i get the exception:

The process cannot access the file '.....\ProductDetails.xml' because it is being used by another process.

I know it is because I just created the file. But is there any way to "let go" of the file after creating it so I can read/write to/from it?

Best regards
Peter

Answers (2)