Solved

write text from database to xml file

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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