473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

filestream write appends even with filemode.create

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
Nov 20 '05 #1
7 3203
Hi Jeremy,

Set xw to nothing after close:
xw = Nothing

HTH,

Bernie Yaeger

"Jeremy" <je****@ninprodata.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2
Cor
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
Nov 20 '05 #3
* "Cor" <no*@non.com> scripsit:
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?

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!
Nov 20 '05 #4
Cor
Herfried,

Can you explain the question something more?

Do you always have a dataset?


Cor
Nov 20 '05 #5
Cor,

* "Cor" <no*@non.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #6
j g
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: GDL | last post by:
Hi, I'm using a FileStream as below: FileStream fs = new FileStream ( filePath, FileMode.Create, FileAccess.Write, FileShare.None
3
by: Muki Rapp | last post by:
Hi! In the example below, once the media is full, the FileSteam.WriteByte throws an exception and the code is designed to handle it. However, when the GC is invoked, it calls the Finalize of...
9
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
11
by: Dorsa | last post by:
HI, Could you please tell me the error in here. I am trying to open an XML file from a link. Response.Clear() Response.Expires = 0 Response.BufferOutput = False Response.ContentType =...
3
by: Terry | last post by:
In the code below, I open a file using filestream, copy it to a byte array, and the write that array out to a new file. But when I check the size of the original file and the new file, the new...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
2
by: ewingate | last post by:
The following code which is supposed to dynamically create files with incrementing names is throwing an exception due to the inclusion of the DateTime.Now component of the sReportSave string: ...
5
by: Bob | last post by:
Hi, Is there any setting that I can use to allow the same file to be open in a filestream in append mode with one process and read in another. I can see why concurrent appends or write modes...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.