the process cannot access the file because it is being used by another process. c# xmltextwriter



I am currently trying to create some code to append to my XML file, it will first check if the file is created and if it is; it will then open the file ready for appending.


But the problem is, is that I am getting the above error message on the last line. If I put existingFile.Close() before this line, the error goes away; but then the data does not append.


Could someone please help me.


Thanks!


I can give the entire code if anyone wishes, but I just though I would give the bit that is giving my an error for now.


Code



if (System.IO.File.Exists(FullPath))
{
found = true;
System.IO.FileStream existingFile = System.IO.File.OpenWrite(FullPath);
existingFile.Seek(-endtag.Length, System.IO.SeekOrigin.End);
writer = new System.Xml.XmlTextWriter(FullPath, System.Text.Encoding.UTF8);
}

No comments:

Post a Comment