473,385 Members | 2,005 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,385 software developers and data experts.

Saving/Loading Xml to/from an Xml file

Hi

I have a function called GetXml that returns Xml as expected.

I then use:
Dim saveFile As New SaveFileDialog
and the configure saveFile.

Having got the file and the Xml, how can I then write the Xml to the file?
Also, how could I load the Xml back in to a string using an OpenFileDialog
(openFile) or similar?

Regards, Carl Gilbert
Nov 12 '05 #1
2 1522
"Carl Gilbert" <cn*@newsgroup.nospam> wrote in message news:OH*************@TK2MSFTNGP09.phx.gbl...
Having got the file and the Xml, how can I then write the Xml to the file?
Dim writer As System.IO.StreamWriter
writer = New System.IO.StreamWriter( _
filename, _
False,
System.Text.Encoding.Unicode)
writer.Write( xmlStr )
writer.Flush( )
writer.Close( )
Also, how could I load the Xml back in to a string using an OpenFileDialog
(openFile) or similar?


Dim xmlStr As String = ""
If ( dlgFileOpen.ShowDialog( ) == DialogResult.OK ) Then
Dim inStream As System.IO.Stream
inStream = dlgFileOpen.OpenFile( )
If ( Not inStream Is Nothing ) Then
Dim reader As System.IO.StreamReader
reader = New System.IO.StreamReader( inStream)
xmlStr = reader.ReadToEnd( )
reader.Close( )
End If
End If
Derek Harmon
Nov 12 '05 #2
Cheers Derek
"Derek Harmon" <lo*******@msn.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
"Carl Gilbert" <cn*@newsgroup.nospam> wrote in message
news:OH*************@TK2MSFTNGP09.phx.gbl...
Having got the file and the Xml, how can I then write the Xml to the
file?


Dim writer As System.IO.StreamWriter
writer = New System.IO.StreamWriter( _
filename, _
False,
System.Text.Encoding.Unicode)
writer.Write( xmlStr )
writer.Flush( )
writer.Close( )
Also, how could I load the Xml back in to a string using an
OpenFileDialog
(openFile) or similar?


Dim xmlStr As String = ""
If ( dlgFileOpen.ShowDialog( ) == DialogResult.OK ) Then
Dim inStream As System.IO.Stream
inStream = dlgFileOpen.OpenFile( )
If ( Not inStream Is Nothing ) Then
Dim reader As System.IO.StreamReader
reader = New System.IO.StreamReader( inStream)
xmlStr = reader.ReadToEnd( )
reader.Close( )
End If
End If
Derek Harmon

Nov 12 '05 #3

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

Similar topics

4
by: Carl | last post by:
In the application I'm writing, I'm modifying a windows bitmap using the circle and line methods. Once the changes have been made, I would like to save the bitmap with the changes. My problem is,...
7
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I...
1
by: Tom | last post by:
I have a large application; lots of forms, multiple dynamic DLLs, etc. I also have, in the appliation, a general 'Preferences' class object (which is in itself a separate DLL, and I just include a...
3
by: Peter Oliphant | last post by:
Trying to save/load a class instance to a file is tough. The reason is because there is no way to preserve its type other than by conventon. For eample, one can save all the states of the members...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
14
by: Simon | last post by:
I'm trying to write a little function to save data. Basically I have a large 2d array of structs, so I'm going to have to call the save function once per struct in the array. I'd like to save the...
10
by: JoeC | last post by:
I am writing a game and all my game pieces are stored in a single vector of piece handles. I have the basics I can read and write char and number files but I am trying to do comthing more...
7
mrnn
by: mrnn | last post by:
Ok I know how to save and load 1 variable from a file, but when it comes to loading multiple variables, I get confused. And all the articles I've found using Google and on here haven't helped too...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.