473,411 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How to save user options and settings to a file, like we used to do with INI files?

I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to a
pristine state and the accumulated user options and application settings are
discarded. What is the accepted way to persist application values to a file
in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Nov 25 '06 #1
4 2618
Hello Richard Lewis Haggard" HaggardAtWorldDotStdDotCom,

RThe app config file appears to be updated with values while the
Rapplication is running but when the application closes, the file
Rseems to get restored to a pristine state and the accumulated user
Roptions and application settings are discarded.

Emm, could u explain what do u mean? Why config is restored?

RWhat is the accepted
Rway to persist application values to a file in a WinForms 2
Rapplication?

One of the approaches, besides xml config, is to use Isolation Storage

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 25 '06 #2
Hi Richard,

"Application Settings Overview"
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

VS 2005 has built-in support for a single, Default Settings file and
Resources file, per project.

--
Dave Sexton

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:OL**************@TK2MSFTNGP03.phx.gbl...
>I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to
a pristine state and the accumulated user options and application settings
are discarded. What is the accepted way to persist application values to a
file in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Nov 26 '06 #3
Settings file? I saw that but was under the impression that it did not lend
itself well to addition and deletion of values programmatically. Did I
misunderstand? Because I thought that it would be difficult to write user
specific application options and MRU list, I deemed that approach
unreasonable. Have I unnecessarily exercised myself in jumping to this
conclusion?

Given that writing an indeterminate number of user specific values to some
sort of persistent storage is such a common requirement, one would have
thought that a consensus as to best practice would have been developed for
which I, only recently having been prized kicking and screaming from the MFC
dark ages, was unaware. I do thank you all for your patience while I flail
randomly about as I try to come up to speed.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:un**************@TK2MSFTNGP06.phx.gbl...
Hi Richard,

"Application Settings Overview"
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

VS 2005 has built-in support for a single, Default Settings file and
Resources file, per project.

--
Dave Sexton

"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:OL**************@TK2MSFTNGP03.phx.gbl...
>>I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to
a pristine state and the accumulated user options and application settings
are discarded. What is the accepted way to persist application values to a
file in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com


Nov 27 '06 #4
Hi Richard,
Settings file? I saw that but was under the impression that it did not
lend itself well to addition and deletion of values programmatically. Did
I misunderstand? Because I thought that it would be difficult to write
user specific application options and MRU list, I deemed that approach
unreasonable. Have I unnecessarily exercised myself in jumping to this
conclusion?
Yes :)

Take a look at the article I posted and you'll see that even controls can
use the Application Settings architecture. For example, ToolStrip uses
Application Settings to save position information of itself and its items
between application sessions.

The ApplicationSettingsBase class provides a Save method that you can call
from your application to persist data (the Save method is actually an
overridden form of the SettingsBase.Save method, from which it derives).
You can even create your own SettingsProvider for persistence outside of the
default local file storage.

Particular settings may be configured to have application-scope or
user-scope in WinForms applications and there is built-in support for
collections as well. IMO, this technology is perfect for persisting a raw
MRU list, per user, as long as the information being persisted isn't
sensitive data that must be secured (although simple, managed cryptography
would probably do the trick).
Given that writing an indeterminate number of user specific values to some
sort of persistent storage is such a common requirement, one would have
thought that a consensus as to best practice would have been developed for
which I, only recently having been prized kicking and screaming from the
MFC dark ages, was unaware. I do thank you all for your patience while I
flail randomly about as I try to come up to speed.
There are no explicitly stated "best practices" that I'm aware of since you
have to consider security, the quantity of the data and the type of the data
(e.g., relational, structured, raw text, raw binary) and because there are
many different places and ways to persist the data (e.g., Application
Settings, application configuration file, Isolated Storage, delimited
flat-file, RDBMS, structured storage, xml file, raw binary file containing a
serialized object-graph, etc.). Application Settings, in the 2.0 framework,
is usually sufficient, but I've seen applications use Isolated Storage, the
application configuration file, an xml file or an RDBMS such as Sql Server
2005 as well.

--
Dave Sexton
Nov 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark S | last post by:
I have a db maintenance plan which is set to backup (then truncate hopefully) the transaction log. In order to backup a transaction log the db must be in single user mode so the maint. plan fails. ...
7
by: Dennis C. Drumm | last post by:
Can my program access the HKEY_LOCAL_MACHINE/Software section of the registry when being used by a user with restricted rights (not with admin rights)? If so, how? I have a program that...
7
by: Arun Kannan | last post by:
Hi We are planning to upgrade a MFC Application (.Exe) to compile on Dot Net Framework. I have opened the application in Visual Studio 2003. I changed the compiler option to /clr. I have set...
4
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
3
by: Robin Tucker | last post by:
I'm a bit confused about where to put my program settings. Firstly, I can choose (I suppose) between .ini, .xml or the registry. Which one is best? Secondly, *where* do I place any files I...
0
by: ssg31415926 | last post by:
I've been trying to save a hashtable in an Application Settings file. I need to save settings for each tabPage on a form. Trouble is, the number of tabPages is determined at runtime, so I can't...
5
by: hp_1981 | last post by:
Hi Is there anyway avoiding users to save my web pages? this idea came to my mind when I tried to save a web page, but in the middle of saving progress something like the following error...
4
by: lfhenry | last post by:
I am a newbie to HADR and Admin of DB2 (I am websphere guy). My question relates to DB2 logging. I've read that HADR does not allow Infinite logging (-1). I am expecting my Database to grow...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.