Solved

write text from database to xml file

Posted on 2008-06-20
3
243 Views
Last Modified: 2012-05-05
Ive got the xml stored in a database (tags and everything). I basically want to just read the cell (stored in one column of one row) and write it out to an file of type .xml.
I did this with streamwriter and it worked fine except that some of the text is getting cut off thus not making the xml file unusable. It seems to be a limit to the amount of data that can be streamed. Is there some way to achieve this?
Is it as easy as writing it to a text file then changing the extension of the text file to .xml?
0
Comment
Question by:slrine2000
3 Comments
 
LVL 10

Expert Comment

by:MrClyfar
ID: 21833994
Hi slrine2000.

Just to check, you said that the data was being cut off - are you sure that all of the xml data is stored in the database column (cell) ? If all the xml data is fine, then could you post the source code you are using to read the xml data and save it to a file?

Cheers.
Jas.
0
 

Author Comment

by:slrine2000
ID: 21834232
'SQL UP HERE
Dim dr As SqlDataReader
        Dim SQLcommand As New SqlCommand(SQL, Conn)
        Conn.Open()
        dr = SQLcommand.ExecuteReader
        Dim objStreamWriter As StreamWriter
        While dr.Read() = True
            'Open the file.
            objStreamWriter = New StreamWriter("C:\Temp\Test.xml")
            txtDisplay.Text = dr.Item(0)
            'Close the file.
            objStreamWriter.Write(txtDisplay.Text)
            objStreamWriter.Flush()
            objStreamWriter.Close()
        End While
        Conn.Close()
I put it to a text box to see if I was returning everything via the datareader because I wasnt sure if there was a limit on the datareader or the streamwriter. It seems that there is a limit on the stream writer.
0
 
LVL 7

Accepted Solution

by:
Dauhee earned 250 total points
ID: 21837441
how about a 1 liner :)
My.Computer.FileSystem.WriteAllText('C:\file.xml', 'xml stuff here', True, System.Text.Encoding.ASCII)

Dont forget to use System.Text.Encoding.ASCII though as you will get some lovely hidden binary chars in it otherwise and can cause all sorts of fun . . . . thats 5 hours of my life I will never get back . . .
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now