goodmorningsky Posted February 20, 2004 Posted February 20, 2004 My app contains options that user can set and the options are applied to app when it is launced. What is standard way to do this? My guess are using App configuration xml file, using Window registry or etc. If you have any code example please post it. Thank you all. Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
dannyres Posted February 21, 2004 Posted February 21, 2004 I think the best way would be for you to use Xml Serialization to write an xml file with all your settings. Heres an example: Make a class with all your options in it: public class Options { public string opt1; public int opt2; public string opt3; } Then create some functions that will serialize and deserialize the info: public static void Serialize(Options Prefs) { //create xml serializer XmlSerializer Serializer = new XmlSerializer(typeof(Options)); //create writer StreamWriter Writer = new StreamWriter(Path); //serialize Data in the options class with the writer Serializer.Serialize(Writer, Prefs); //close the writer Writer.Close(); } public static Options Deserialize() { //create xml serializer XmlSerializer Serializer = new XmlSerializer(typeof(Options)); //create reader StreamReader Reader = new StreamReader(Path); //deserialize the xml and load it into the Prefs variable Options Prefs = (Options)Serializer.Deserialize(Reader); //close the reader Reader.Close(); //return the Options return Prefs; } Tell me if you need me to explain a little better. :) Dan Quote
SEVI Posted March 30, 2004 Posted March 30, 2004 Hi I have a question one this serialization example. Could the above sample be easily modified to handle multiple objects that have been serialized? I know conceptually it dosn't work in this case, as there would only ever be one "options" object per project, but for the sake of the exercise could this be done. The serialization isde is ok, I guess you'd just dupe the "Serializer.Serialize(Writer, Prefs);" line per object. What about when deserializing? How do you specify the object to deserialize? Thanks a heap! SEVI Quote
Threads Posted March 30, 2004 Posted March 30, 2004 Check out this example Here is a cool example that includes serialization of a class to save settings.... It also shows how to store it in multiple ways. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchCreateYourOwnDynamicPropertiesPreservePropertySettingsInVisualBasicNET.asp Quote mov ax, 13h int 10h
Threads Posted March 30, 2004 Posted March 30, 2004 Updated Example I'm sorry, the link I posted was incorrect. Now I can't seem to find the proper article. However, I still have the source download from the article, which also includes a copy of it in a Word document. I have attached it here.vbUserSettings.zip Quote mov ax, 13h int 10h
Threads Posted March 30, 2004 Posted March 30, 2004 Of course, the moment I post this, I find the correct link. http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07082003.asp?frame=true Quote mov ax, 13h int 10h
SEVI Posted March 30, 2004 Posted March 30, 2004 Of course' date=' the moment I post this, I find the correct link. http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07082003.asp?frame=true[/quote'] Thanks.. I'll check it out! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.