   [.net] Saving a XML document
//how load the xmlpublic Form1()   {  InitializeComponent();  sr = new System.IO.StreamReader(@"test.xml");  xr = new System.Xml.XmlTextReader(sr);  scoreDoc = new System.Xml.XmlDocument();  scoreDoc.Load(xr);   }//how i save the xml and close formprivate void button3_Click(object sender, EventArgs e)   {  scoreDoc.PreserveWhitespace = true;  scoreDoc.Save(@"test.xml");  this.Close();   }everything compiles fine, until I get this: The process cannot access the file 'D:\Program Files\Microsoft Visual Studio 8\Visual Studio 2005\Projects\Lesson10\Lesson10\bin\Debug\test.xml' because it is being used by another process.The only process "using" it is VS 2005. So how do I expect someone to save changes to an XML documents if the program won't let it because the program is using it?!I'm confused. Need help. [sad]note: I've tried it with and without the '@'. Still get same error.   
  I believe you have to close the XML file.You should do this by calling the XmlTextReader.Close method after you call save. For example:private void button3_Click(object sender, EventArgs e){    scoreDoc.PreserveWhitespace = true;    scoreDoc.Save(@"test.xml");    scoreDoc.Close();    this.Close();};  so I have to make a xmlReader, load it to a xmlDocument, then somehow load it to a xmlReader?i can't use the code you provided because Close() is in the xmlDocument class.   ;  I'm guessing, but I think the StreamReader needs to be closed before "test.xml" is released.It looks like you need to call sr.close() before attemting to save.// UNTESTED!//how load the xmlpublic Form1()   {  InitializeComponent();  sr = new System.IO.StreamReader(@"test.xml");  xr = new System.Xml.XmlTextReader(sr);  scoreDoc = new System.Xml.XmlDocument();  scoreDoc.Load(xr);  // added  sr.close();   }//how i save the xml and close formprivate void button3_Click(object sender, EventArgs e)   {  scoreDoc.PreserveWhitespace = true;  scoreDoc.Save(@"test.xml");  this.Close();   };Quote:Original post by Im_wasting_my_lifeI'm guessing, but I think the StreamReader needs to be closed before "test.xml" is released.It looks like you need to call sr.close() before attemting to save.*** Source Snippet Removed ***yuo r teh Winnar!! ++for you!!edit: actually ++Maxamor too, because he gave me the answer but I read the code, not the answer.   