473,386 Members | 1,706 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,386 software developers and data experts.

Where do settings get saved once the application is running?

Hello
I would like to find out where (in what file) do settings get saved when my application runs (made with windows forms - after i publish my application, not when i debug it). All my settings are saved with the Scope being "User" and the default value being 0.
For example i got this code
Expand|Select|Wrap|Line Numbers
  1. int x;
  2. x = Properties.Settings.Default.xSetting;
  3. private void buttonAdd_Click(object sender, EventArgs e)
  4. {
  5.   x++;
  6. }
  7. private void buttonSave_Click(object sender, EventArgs e)
  8. {
  9.   Properties.Settings.Default.xSetting = x;
  10. }
  11.  
So when i click the buttonAdd button it increase the x, when i click the buttonSave it saves the setting. I know where the default setting is saved, i cant find any file where the new settings are saved, the ones that change from one runtime to the other.

Thanks anticipated.
Oct 2 '11 #1

✓ answered by arie

To get the path of your user config file (when the application is installed and running), first add the reference to System.Configuration.dll. Next execute the code:
Expand|Select|Wrap|Line Numbers
  1. string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
In the localization Application.ExecutablePath there are only Application settings, and in /bin folder of your project there is a file where you'll see your User settings, but they won't change. The real path is the one you'll get using the code above.

24 13342
adriancs
122 100+
You can simply write it into a text file.
For more advance options, save it into embed database, such as SQLite.
Oct 4 '11 #2
Yes that did cross my mind (about the txt file) but i was hoping i can find them somewhere in an xml file (since the application knows the saved settings after closing and reopening it)
Oct 4 '11 #3
GaryTexmo
1,501 Expert 1GB
He's talking about the built in settings class.

Here's the MSDN page for Settings. Take a look at the section entitled, "Changing the Value of a Setting Between Application Sessions"

http://msdn.microsoft.com/en-us/libr...tingscs_topic3

There should be a file somewhere (probably your executable folder) with a name that looks like: <AssemblyName>.exe.config
Oct 4 '11 #4
I've looked over that several times, I got a [appname].exe.config.deploy (after i install it on my computer) and one [appname].exe.deploy
The problem is that the .exe.deploy one is unreadable and the first one contains all the settings with the 0 value, even though in my application they increase and save themselves reloading the same values when i reopen the application.
Oct 4 '11 #5
GaryTexmo
1,501 Expert 1GB
Oh are you running this as a ClickOnce application?
Oct 4 '11 #6
Yes, indeed i am :)
Ive heard people using others but its kinda complicated for me to find another program to compile it, i would though if it would show me the settings file!
Oct 4 '11 #7
GaryTexmo
1,501 Expert 1GB
Ahhhh, you should have mentioned that at the start :D

The thing with ClickOnce is, the application folder gets set to something really strange and can be pretty tough to find. I think it's in something like (Vista/Win7):

c:\users\<you>\appdata\local\apps\<random set of chars>\<random set of chars>\<something that looks logically reasonable>

That probably looks confusing, but try to follow it and hopefully you'll see what I mean. If you're using XP or another OS, just google "ClickOnce installation location <your OS name here>" and you'll likely find it. Anyway, your config file should be in there.

Another option might be to put some code in your program to output the startup folder or the executable path. Take a look at the Application Class as there's all sorts of helpful stuff in there :) So for example, in your Form's Load event, you could put something like...

Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(Application.ExecutablePath);
or you might even want to output it to a textbox somewhere so you can copy/paste it (I recommend some kind of debug window... basic example here: http://bytes.com/topic/c-sharp/insig...y-debug-window).

Are you just looking for this to validate some of the settings, or do you actually need to edit it by hand sometimes? If the latter, you might want to look at storing it in the user's folder instead of the application folder. I believe you can manually move this around but you'll have to do some digging to find out how, as I don't know off the top of my head.
Oct 4 '11 #8
Thanks mate, i couldn't find it though, the folders were either empty or full of clicksomething . manifest or so, no config whatsoever. I decided i should stop using settings to save my stuff, and instead save them to an .xml file with xmlreader since as ive heard, it more efficient (resource-wise)
But thank you very much
Oct 4 '11 #9
GaryTexmo
1,501 Expert 1GB
There should be a folder in there called <blahblah>_app maybe? I honestly can't remember and don't have a ClickOnce application handy to test with.

Also, while I too would advocate handling it yourself over using Microsoft's built-in way, you're going to run into the same problem unless you store it somewhere specific (not recommended). Anything running out of the executable folder will be in that goofy ClickOnce installation path.
Oct 4 '11 #10
I've found the path with
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(Application.ExecutablePath);
  2.  
Great thinking btw :D , sadly the config file there is with the default values. Will make the XML file and check if it turns up in there. Thank you
Oct 4 '11 #11
arie
64
To get the path of your user config file (when the application is installed and running), first add the reference to System.Configuration.dll. Next execute the code:
Expand|Select|Wrap|Line Numbers
  1. string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
In the localization Application.ExecutablePath there are only Application settings, and in /bin folder of your project there is a file where you'll see your User settings, but they won't change. The real path is the one you'll get using the code above.
Oct 5 '11 #12
I'm sorry but it pops 3 errors:
1. it wont allow me to add ".dll" at the system.configuration
2. it says that ConfigurationManager does not exist in the current context
3. it says that ConfigurationUserLevel does not exist in the current context

I've removed the .dll and that fixed one problem.
Oct 5 '11 #13
arie
64
In your Solution Explorer click References and add System.Configuration (it'll be called this, without .dll extension, although on disc, in your Framework folder, it has it :)). Then add
Expand|Select|Wrap|Line Numbers
  1. using System.Configuration;
to your code. Then it'll work.
Oct 5 '11 #14
Awesome, it worked. Thanks a lot :D
Oct 5 '11 #15
A last question, i've heard people saying that saving data in settings isn't so efficient as saving it in an XML. Is that true? Since saving in the settings is much easier than the XML stuff.
Oct 5 '11 #16
GaryTexmo
1,501 Expert 1GB
Cool post, arie, I didn't know that :) For those of us who don't have a ClickOnce app to test with, Andrei, can you post what the path looks like? I'm curious :D

As for your last question, honestly, I think it boils down to preference. In terms of efficiency, computers are fast these days... unless you're reading/writing to that settings structure heavily on a real time basis, you really won't have to worry about it. By the same token, it's not terribly difficult to write your own settings storage mechanism. So if you're comfortable with the built in settings stuff and performance isn't an issue, I'd say stick with it.

If performance is an issue, do some tests. Do some performance scenarios and check the timings with a performance timer, such as a Stopwatch which lives in System.Diagnostics. You can instantiate one, then start it. Now do your test, then stop it and check the elapsed time. Then do the same with your own stuff and compare.

Keep in mind that neither of these storage mechanisms need to access the file system on a regular basis, only on program start and close, as that's when the settings need to persist. I'm not sure what the Microsoft mechanism has, but some people might include a timed save in their own to ensure values are not lost if the program crashes, but for the most part, the values will change in-memory.
Oct 5 '11 #17
Well my application when i debug it has this configuration path:
C:\Users\[my user name]\AppData\Local\Microsoft\MainFrame.vshost.exe_Stro ngName_qkllcxzawdnpexuhgvdo4141qzecd3sw\1.0.0.0\us er.config

When i publish and install it its here:
C:\Users\[my user name]\AppData\Local\Apps\2.0\Data\XZZMY5EO.68H\ZGPB4VPK .09L\main..tion_2f092bac042a4cc2_0001.0000_adb1741 db8a6d54b\Data\1.0.0.0\user.config

(the last part changes slightly if i publish again and install a newer version -even if i don't change anything inside it-)

And yea...i'll have to think about what to use, i need to save my data so that when new versions of the program can appear, the user wont lose his data when updating the program (mainly was thinking of making an uninstall button that will save the SavedData file somewhere safe, then uninstalls the program after which the user installs the new version and i put a load path button to let the user indicate where the SavedData file is stored - i know theres an updating feature in visual studio but it seems too complicated for me at the moment- )
Oct 5 '11 #18
GaryTexmo
1,501 Expert 1GB
Ah ok, cool, thanks for posting where it is :)

ClickOnce does indeed have an update feature. If it detects a new version on the client, depending on your settings, it will either automatically give them the new version or ask them if they want to upgrade. I think anyway. If your settings file keeps track of a version, on load you can always compare the current version with the one stored in the settings file, then manipulate the data as required to bring it forward.

ClickOnce has a version number (on the Publish tab of your project's settings) that will increment with each publish. You can use the following code to get the version number...

Expand|Select|Wrap|Line Numbers
  1. Version myVersion;
  2. if (ApplicationDeployment.IsNetworkDeployed)
  3. {
  4.    myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
  5. }
  6. else
  7. {
  8.   // you probably ran this from your debug, or directly from the binaries. The version number will be from the project settings here but not the publish tab. It'll likely be 1.0.0.0 if you haven't changed it.
  9. }
Oct 5 '11 #19
Hmmm but how does ClickOnce update the application? Does it uninstall the old one and install the new one? Or can it just replace some files without uninstalling anything?
Oct 5 '11 #20
GaryTexmo
1,501 Expert 1GB
No it doesn't uninstall it, it just updates the binaries in the installation folder.
Oct 5 '11 #21
:O

I must learn how! I've read a lot about it but every "guide" was really complicated, they said first i must make an xml with the version, then compare the 2 versions (the new one and the old one) and if bla then bla, if not then....ugh, i kinda stopped there since there were a few pages. Do you know any cleaner solutions?
Oct 5 '11 #22
GaryTexmo
1,501 Expert 1GB
Check the options on the publish tab, there should be something that asks how your application should check for updates (and possibly what it should do about it). Have a look in there.
Oct 5 '11 #23
I need to upload it on the net first, and i don't know exactly what to upload, the WHOLE source? Neither do i know how to upload it, as in, most uploading sites give you the site where if clicked you automatically start the downloading process.
Oct 5 '11 #24
GaryTexmo
1,501 Expert 1GB
When you click the publish button on the publish tab, it will generate files. This is what you put on your server. The user will run the .application file and it will deploy to their machine. You also have to put the site/folder it deploys from in the publish information.
Oct 6 '11 #25

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Imran Aziz | last post by:
Hello All, I have developed an ASP.net application using the latest beta release (version 2 beta 2)of dot net using Visual studio .net express edition. I have been testing the application using...
1
by: Karunakararao | last post by:
hi all Can't Shutdown with System Tray Application Running in C#.net Regards Venu
3
by: Ashish | last post by:
I have a application in which culture settings are customizable, they dont depend on the machine settings on which the application is running, I need to make sure that all the threads running in...
1
by: Bob Rock | last post by:
Hello, how do I get from the application itself the root (or bin) folder where the asp.net application is running??? Regards, Bob Rock
2
by: Tim Diggle | last post by:
I'm trying to enter data into a database application running under Citrix ICA Client. I'm doing it from a VBA macro running under Microsoft Excel 2000 (although it may need to be backwardly...
0
by: Rodney | last post by:
I want to provide a small Click Once application to a small number of selected users, when the application is published on an otherwise public web server (I don't want everyone to have access to my...
0
by: reifen-straub | last post by:
Hi, we have a C# click once application with a report. This report has a reference to an assembly to calculate some things. If we run this application locally with the 'click once' checkbox...
1
by: krach.aran | last post by:
I'm creating a winforms click-once application that is plugin enabled. The application is working, and so are the plugins. but now i have got the following problem: after deployment i do not...
1
by: rkvausi | last post by:
Hi All, Is anybody can help me to find out relation between click once application and web page? I opened one window application from my web page and i want that as soon as I closed that application...
4
by: Max2006 | last post by:
Hi, I am developing a web application on windows XP. A page within my application needs to access to SSRS running on the same machine. Once the web application tries to consume the SSRS web...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.