filestream write appends even with filemode.create

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

I have a procedure that writes an xml file to disk. When I click my button
and run it once, it replaces the xml file on disk as it should. If I click
the button a 2nd time, it appends. If I leave the app & click the button,
the file is replaced.

I've tried closing and flushing, but no joy. Dispose is not an available
method. Any thoughts?

Here is a snippet (ds is a dataset):

Dim tw As New System.IO.FileStream("filedrive:\path\name.xml",
IO.FileMode.Create)
Dim xw As New XmlTextWriter(tw, System.Text.Encoding.UTF8)
ds.WriteXml(xw, XmlWriteMode.WriteSchema)
xw.close()

Jeremy
 
Hi Jeremy,

Do you know that this is enough to write a dataset and schema to disk?

ds.WriteXml("filedrive:\path\name.xml", XmlWriteMode.WriteSchema)

Cor
 
* "Cor said:
Do you know that this is enough to write a dataset and schema to disk?

ds.WriteXml("filedrive:\path\name.xml", XmlWriteMode.WriteSchema)

Do you always have a dataset?
 
Cor,

* "Cor said:
Can you explain the question something more?

Oh, I feel sorry, I missed the 'ds' in the OP's post. I'll clean my
glasses now.
 
Bernie, turns out that I was not clearing my source dataset, so when I
re-filled it and looped through it again to write my output ds, the
source had duplicate records. The writexml code was working correctly
all along.

Jeremy
 
Cor, no, I didn't know that. The dox led me to believe that the syntax
you suggest would only write the schema. Sure is simpler.

Jeremy
 
Back
Top