DataSet.WriteXML doesn't close the file?

U

UJ

It appears when you do a DataSet.WriteXml ( <filename>, <writemode> ) it
doesn't close the file immediately.

Is that true ? The reason I think that is I have two programs that are going
to be access the same XML file and when one writes to it the other can't
seem to read it.

I've also tried running in the debugger and stopping the program on the line
after the file is written, go to the next line and then attempting to open
the file. I can't until I close the debugger.

Any suggestions?

TIA - Jeff.
 
J

John J. Hughes II

I have never tried to get the WriteXml function to close the stream so I
don't know if there is a way of doing it but this is how I handle writing to
XML. You can ignore the Xceed part and just use anything that opens a
stream.

private void WriteToFile(Xceed.FileSystem.AbstractFile sentFile)
{
using (System.IO.Stream stream = sentFile.OpenWrite(true))
{
XML.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = false;
XML.XmlWriter xw = XML.XmlWriter.Create(stream, settings);

xw.WriteStartDocument();
xw.WriteStartElement("root");

this.WriteData(xw);

xw.WriteEndElement();
xw.WriteEndDocument();
xw.Close();
stream.Close();
}
}
 
U

UJ

Thanks. I also am going to try and open a filestream, do a WriteXml (
filestream ) and then forcibly close it. Hopefully that will fix the
problem.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top