C# Newbie - Load and Save TextBoxes to XML

0 Alexander Perez · April 19, 2015
Hello all.  I'm new to C#.  I'm hoping someone can steer me the right direction.  I'm trying to accomplish the following:

1) Fill in Text Boxes and save its contents as an external xml file for later use.  
2) Also need to be able to open/load it via file browser.  

I've been able to get the open file browser to work (using OpenFileDialog) 
Also have been able to get the Save-as to work via file browser (using SaveFileDialog)

Where I'm stuck is the code to actually save each textBox I have while in the SaveFileDialog.  

I have seen various examples on YouTube but they seem to be using an "automated saving method" that drops a file in a specific location without allowing you to choose your own location or file name.  

I basically would like the user to be able to fill out the designated fiends and be able to save their work.  Additionally, be able to open blank application and open the saved file back.  

Your help is great appreciated.  

Post a Reply


Oldest  Newest  Rating
0 Bill Harding · April 21, 2015
Are you saying you want the user to save a file locally?
Is this a web application?

If so here is what I have done. 
Create a save button executes servers side. 
When clicked the contents of the box are converted to xml
Then you set the response header to application/download and set the appropriate file name header.
then write the xml to the response. 
then you close the response.

the browser will see the response as a download and prompt the user for a location. Where depends on teh prowser. usually Downloads but they can pick anywhere.

I use this on tables with a save to excel button. What i like about it is that the server never actually creates a file, it only looks like it on the client.

in the button click event...

var xml = // convert your stuff to xml
Response.AddHeader("Content-Disposition", "attachment; filename=" +FileName);
Response.AddHeader("Content-Length", xml.Length.ToString());
Response.ContentType = "application/download";
  • 1



C# is an object-oriented language designed for improving the development of web applications.