Solved

write text from database to xml file

Posted on 2008-06-20
3
242 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

13 Experts available now in Live!

Get 1:1 Help Now