Structures and Settings

3 views
Skip to first unread message

Markarina

unread,
Nov 24, 2009, 7:15:28 AM11/24/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have a program that the user defines a bunch of settings which I
store in structures and would like to preserve between program runs,
normally I would just save these as settings under the project-
>properties option, but there does not seem to be add user defined
variable types to the type options.

The other option would be to get save the data on exit and get the
user to load it on start up but that seems a little clunky.

Processor Devil

unread,
Nov 24, 2009, 7:46:02 AM11/24/09
to dotnetde...@googlegroups.com
What about App.Config ?

2009/11/24 Markarina <mar...@googlemail.com>

Raghupathi Kamuni

unread,
Nov 24, 2009, 7:49:16 AM11/24/09
to dotnetde...@googlegroups.com
Why not use web.config?

Markarina

unread,
Nov 24, 2009, 8:31:49 AM11/24/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
okay App.Config would seem to be the way to go, however since windows
programming and XML are not part of my core skillset, can somebody
give me some pointers how I add an array of structures and their
component values to the file, and then read and write to the
App.Config?

apologies if this seems to be a dumb question but not had to dig down
to this level before

On Nov 24, 12:46 pm, Processor Devil <processor.de...@gmail.com>
wrote:
> What about App.Config ?
>
> 2009/11/24 Markarina <mark...@googlemail.com>

Processor Devil

unread,
Nov 25, 2009, 3:16:30 AM11/25/09
to dotnetde...@googlegroups.com
Nah, try to read something about App.Config first, it is really easy to use.
In case of XML, I am lazy bastard as well, I rather use DataTable to read and write xml, just sometimes I really need XPath... :D
So, if I say that App.Config is easy to use then it is really easy...

2009/11/24 Markarina <mar...@googlemail.com>

Markarina

unread,
Nov 26, 2009, 12:19:54 PM11/26/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I've done a bit more digging and it seems that app.config is mainly
intended for settings that are changed rarely, and the nature of the
settings I am using is that they will probably change each time the
application is run. Also if I'm being honest having found some code
snips that show how to use app.config I can't get them to compile.

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration
(ConfigurationUserLevel.None);

config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

gives the error

The type or namespace name 'Configuration ' does not exist in the
class or namespace 'System.Configuration' (are you missing an assembly
reference?)

I also get " the name 'ConfigurationManager' does not exist in the
current context"

I'm probably being thick, but what am I missing?

The other information suggests using "xmlserializer"

Jamie Fraser

unread,
Nov 27, 2009, 10:59:49 AM11/27/09
to dotnetde...@googlegroups.com
Save the data as XML on shutdown.

Load this on startup.

Or serialise it to a Db table (if you have a DB).

App.config / web.config are not for this kind of scenario.

Markarina

unread,
Nov 27, 2009, 7:05:49 AM11/27/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Ok yes I was being thick - DOH!

Brynn V1.0.0

unread,
Nov 27, 2009, 4:45:24 AM11/27/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I would maybe try Application variables in the web.config file ...
that then can be easily set from c#.
I would also look at the HttpModule that many like to use for
App begin, request begin, error ... it is also a helpful spot.

http://msdn.microsoft.com/en-us/magazine/bb985530.aspx

Now, the application by default terminates after 29 hours of no use.
I personally would throw them in a text file and have the text file
values updated with a special class just for that, at the same time
the Application variable itself changes.

Then, when the HttpModule's Init kicks in ... after the App has
died and is coming back to life ... you can reload those values
into the App with a quick private function in HttpModule class.

This all assumes the changes to the App variables are going to
be done dynamically vs manually.

Anyway, take care.
Reply all
Reply to author
Forward
0 new messages