Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Suggestions for Workstation Config File
Message
De
17/03/2003 17:48:17
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00766747
Message ID:
00766790
Vues:
33
This message has been marked as a message which has helped to the initial question of the thread.
The simplest way would be to save the settings to an .ini file. I don't know off-hand whether .NET has any built-in classes for parsing a standard .ini file but I suspect they are in there somewhere.

However, a more elegant solution is to define a class with public properties that hold the settings. Then you can use the built-in XMLSerialization class to save and load the settings from an XML file directly into an object. The following code comes from the VS.NET help system page
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconintroducingxmlserialization.htm
Dim myObject As MySerializableClass = New MySerializableClass()
' Insert code to set properties and fields of the object.
Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(MySerializableClass))
' To write to a file, create a StreamWriter object.
Dim myWriter As StreamWriter = New StreamWriter("myFileName.xml")
mySerializer.Serialize(myWriter, myObject)
Some key points on serialization:

1. Only public properties and fields are serialized, private properties and fields are ignored.

2. You can add tags to your class definitions to tailor the format of the XML file. For instance, the nodes created in the XML file will match the name of the properties and fields of your class. The node names can be overridden by adding the XmlElement tag to the class declaration:
Public Class TaxRates
   <XmlElement(ElementName = "2ReturnTaxRate")> _
   Public ToReturnTaxRate As Decimal
End Class
3. If you decide to add more properties and fields to your class at a later time, you will not have to modify the code that stores and retrieves the XML file. The XmlSerialization class will accomodate the changes on the fly.

4. If you are using this technique in a web forms or web service project, you will have to add some code to read and write the XML file on the client workstation and not on the server (web forms and services run directly on the server). Or you can use the user name or workstation name as the XML file name and keep the files on the server.

I suggest perusing the VS.NET help files with the goal of gaining a complete understanding of the relationship between objects and serialization, since it is one of the fundamental concepts in .NET and you will encounter it in almost every project that you undertake.

Good luck!

>I need to create a config file for the Windows application all winforms. I'm using vb.net. The first time the application is run, it will prompt the user for certain information such as SQL Server name/ip, Default choices on color selection etc. I want to store this in a config file for the next time.
>
>How might be the best way to do this. Right now in foxpro, I save these to a mem file, then I just restore from them. I'm sure it is a little more complex in vb.net. Thanks for any help. (details welcome...I'm very new to this stuff)
>
>Kirk
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform