|
-
March 7th, 2005, 05:05 PM
#1
Config File?
Hi,
In my application, eventually during install I would like a bunch of setting to be chosen, and that can also be changed in the program itself, for example:
path to Access DB, or maybe future change to any kind of DB.
Create Access DB from scratch?
Certain fields like in the title bar will be Organizations X application
where they can change the title bar, etc
But one of the main reasons are for flexibility. For my payroll application the user must chose if there are options a position to punch in as.
So say front, back, drive thru etc (if it was say a fast food place), now if say some other org uses my app they might need, desk, shelver etc (a library). I dont want to hardcode these in as thats counter productive. So I need a way of changing what options are available. This information would need to be kept somewhere.
Im not sure how this is typically done as Im a new programmer, so what I was thinking is a configuration file (probably XML?) which would be read upon launch to set all the settings that I would need.
Would this be the correct way to store settings? Also if this is where would I go about learning how to implement this?
Thanks!
Will Rate Posts for help!
-
March 7th, 2005, 05:33 PM
#2
Re: Config File?
XML sounds right. You can do two things:
1. Add an Application Configuration File to your project (App.Config), and then add a configuration section. This configuration file can be read automatically by .NET.
See ConfigurationSettings object and Configuration Files in the MSDN. It shows there exactly what is the correct format of the xml with example, and how to read it.
2. Create your own XML. There are lots of ways to read XML files in .NET (DataSet.ReadXML, XMLDocument object, ...).
-
March 7th, 2005, 05:48 PM
#3
Re: Config File?
First way sounds much easier, Ill look into that.
Will Rate Posts for help!
-
March 7th, 2005, 07:22 PM
#4
Re: Config File?
Ok so I read this article:
http://www.codeguru.com/columns/DotN...cle.php/c7987/
The custom and groups is a little over kill for me right now, so I just did the
Code:
<appSettings>
<add key="key1" value="key1svalue">
...
ok so In designer im getting this funky error which im sure must have something to do with the name of my config file.
Within the windows forms designer generated code I did this:
Code:
this.Text = ConfigurationSettings.AppSettings["ApplicationTitle"];
its crying about something or other, maybe I cant add this in the designer code, and should change it to be in the onload or something.
Anyways my projects name is Payroll.csproj
and the config gile is Payroll.config
do I need to change it to the forms name?
Thanks in advance.
Will Rate Posts for help!
-
March 7th, 2005, 08:42 PM
#5
Re: Config File?
I use
Code:
this.Text = ConfigurationSettings.AppSettings.Get("ApplicationTitle");
-
March 8th, 2005, 03:12 AM
#6
Re: Config File?
Ctwizzy,
I don't think this article is the one you want.
a) The app.config file is read-only and I thought you wanted to save values as well
b) I'm sure this file is only read at run-time so you can't use its values in the visual designer.
Try here instead for some ideas: Saving Config. Something new for .NET is something called Isolated Storage, but I haven't really looked into it.
Useful? Then click on (Rate This Post) at the top of this post.
-
March 8th, 2005, 10:31 AM
#7
Re: Config File?
jhammer, that was the format...
Norfy, thanks ill look into that. So no saving into a config file? How do applications do it then, to update configuration settings that users do. Kind of like adobe, or firefox or anything. How does the app know to load those settings instead of the default?
Will Rate Posts for help!
-
March 8th, 2005, 10:54 AM
#8
Re: Config File?
 Originally Posted by Ctwizzy
So no saving into a config file?
That's not what I said. There is no saving to the app.config file.
How do applications do it then, to update configuration settings that users do.
Follow the link I posted and find out...
Useful? Then click on (Rate This Post) at the top of this post.
-
March 8th, 2005, 12:16 PM
#9
Re: Config File?
You know sometimes I feel like an idiot. I spent all this money on Chris Sells Windows Forms Programming in C# and I never look in it, I always run to the forum.
I have yet to check that link out, but the book has an entie chapter on .config files, and alternatives to the read only config files such as:
Registry, Special Folders, Settings and Streams, and Isolated Storage (as you pointed out norfy).
Im going to read up on this chapter and start coding, If I run into any problems then ill come back here 
Thanks a ton!
Will Rate Posts for help!
-
March 8th, 2005, 12:53 PM
#10
Re: Config File?
Ok so Norfy quick question.
Do you advise using the dll that guy created for doing isolated storage, or should I learn to code it myself via opening the streams writing etc?
Thanks!
Will Rate Posts for help!
-
March 8th, 2005, 05:00 PM
#11
Re: Config File?
Do you advise using the dll that guy created for doing isolated storage
isolated storage.... U should be very careful with it. It is easy to accidently make it dependant on assebly version/name etc. Than user could loose all setting after upgarde .
And this library.... it works (very good indeed) but it is so poorly written, not optimised, very slow. IMHO it is only starting point (but very good starting point )
or should I learn to code it myself via opening the streams writing etc?
It is allways beneficial!
Best regards,
Krzemo.
-
March 8th, 2005, 05:53 PM
#12
Re: Config File?
Yes I found a Configurartion .CS file which shows how to do all the reading writing using Isolated Storage. Makes enough sense so im using it, I have noticed that it is a little slow but my boss is hampering me daily to get this over with, so if hes disappointed with speed after its up and running ill go back and fix it then.
Thanks Krzemo
Will Rate Posts for help!
-
March 9th, 2005, 02:43 AM
#13
Re: Config File?
Have you read the article yet? 
Like the article, if you interact with your config code through an interface then you can easily change your mind at a later date and put an alternative implementation in place.
Useful? Then click on (Rate This Post) at the top of this post.
-
March 9th, 2005, 10:47 AM
#14
Re: Config File?
Ill take a more thorough look later tonight thanks norfy.
Will Rate Posts for help!
-
March 9th, 2005, 11:21 AM
#15
Re: Config File?
Hi Ctwizzy.
I often save settings in the Registry, instead of using my own files.
Note that if you want to write files on the machine, you must be sure that you have the rights to do it. So if you choose to save a file you can't do anywhere on the disk. For example you can't do it in the Application.ExecutablePath which could be write protected, if Windows was started by a user who doesn't have the administrator rights.
If you do it in the registry, you can save your settings in HKEY_CURRENT_USER\Software\Your company\Your app
Every user of the computer will have its own settings, which is quite nice, don't you think?
Mr. Burns
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|