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 -
int x;
-
x = Properties.Settings.Default.xSetting;
-
private void buttonAdd_Click(object sender, EventArgs e)
-
{
-
x++;
-
}
-
private void buttonSave_Click(object sender, EventArgs e)
-
{
-
Properties.Settings.Default.xSetting = x;
-
}
-
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.
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: - 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
You can simply write it into a text file.
For more advance options, save it into embed database, such as SQLite.
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)
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
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.
Oh are you running this as a ClickOnce application?
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!
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... - 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.
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
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.
I've found the path with -
MessageBox.Show(Application.ExecutablePath);
-
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
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: - 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.
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.
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 - using System.Configuration;
to your code. Then it'll work.
Awesome, it worked. Thanks a lot :D
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.
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.
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- )
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... - Version myVersion;
-
if (ApplicationDeployment.IsNetworkDeployed)
-
{
-
myVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
-
}
-
else
-
{
-
// 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.
-
}
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?
No it doesn't uninstall it, it just updates the binaries in the installation folder.
: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?
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: Karunakararao |
last post by:
hi all
Can't Shutdown with System Tray Application Running in C#.net
Regards
Venu
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
| |