Properties files

stowell_48

Member
Joined
Sep 11, 2006
Messages
5
Programming Experience
1-3
Hi, this is my first time posting on the forums, also I am new to the .net language.

I am trying to create a properties file that contains data that my program will load in upon program launch.

For example: I have in my properties file the path to the location of another application that will be controlled through my program. This path will change from computer to computer so it needs to be in a file that the user can change for each system.
Also I would like to have in the properties files other variables that are computer specific.

so if I was writing internet explorer, it would be comparable to internet options where the user can put in their own Home page settings. etc...

What is the best way to go about doing this? Do I need to create all the reading and writing of the files to a particular file that I create? Or is there a library that I can call that has these functions build in?

Please let me know how I can go about solving this problem

Thanks for you help.
 
Then why does it say "Primary Platform: .NET 2.0 (VS 2005)" on your post?

.NET 1.x doesn't have that same functionality. I would suggest defining a class with a property for each of the settings you want to persist and then you can use XML or binary serialization to read and write the data.
 
There is no one that is incorrect in this post, but the correct way to do this is debatable. If you want to go with the masses (This is not recommended), you can store it in the registry. Now this is not recommended, because the .net framework is XML friendly, and it's really the best way to store the information. Microsoft uses these xml config files on almost all there recent enterprise solutions.

The options with XML are very straight forward. By default, any new Windows Application will create a app.config file. This file as soon as you build the app will be renamed to application.Config, where application is the name of the app (i.e. MyApp would have a myapp.config). You can always wite the user properties to this, but the best way to keep it clean would be to write to a completely seperate xml file and call it whatever you want. To find information about this do a search on google or msdn for write to xml and read from xml. It should give you all the information you need. To save you some time, the best way is to do this is as it was stated in one of thes posts to create a custom class with all the properties that you want to set in it, then serialize the object. But if this is confusing you can achieve the exact same results and it may be a lot easier for you to understand, if you just write code to read and write the xml. I would suggest that approach if you are not very comforitable with .net yet.
 
Back
Top