c# - How to save settings from an windows form app using a savedialog -


i have word search creator app. user inputs list of words, width , height settings, word placement settings etc. when user clicks save button, these settings saved file, later user can open app saved settings. have no idea how though. (except opening savefiledialog)

the savefiledialog provides application gui save window allows user choose save location , filename. dialog comes event handler (which believe called fileok) can access mysavefiledialog.filename .

no data or file has been saved yet. that, take variety of routes, simplest using system.io.streamwriter:

using system.io; ... streamwriter sw = new streamwriter(mysavefiledialog.filename); //pass chosen filename sw.writeline( string goes here ); sw.close(); 

you'll have come string representation of data, though.

for more complex types, use xml serialization. can define data structure class , use .net's built in system.xml.serialization namespace automatically output representation of class easy read xml file:

public class mywordgame {    public string[] mywords;    public int height;    ... }  ... xmlserializer xmlout = new xmlserializer(mywordgame.gettype()); xmlout.serialize(new filestream(mysavefiledialog.filename), new mywordgame()); 

you can reverse (deserializing) recover original class xml file

there plenty of tutorials xml serialization out there should at.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -