1

I added a settings file in my service application developed by C# in VS2008. In the designer of settings file, i inserted new datetime variable with user scope and entered default value for that datetime variable. For instance, suppose that the name of this variable is MyDate and its value is "2013-01-08".
When i run my service application, i get the value of MyDate correctly with the following code line:

Datetime value = app.Default.MyDate; // app is the name of the settings file

After that i set MyDate to "2013-01-08 14:00:00" with the following line of code:

app.Default.MyDate = DateTime.Now; // Suppose Now is 2013-01-08 14:00:00 at that time.
app.Default.Save();

Everything is OK until now. MyDate parameter is set to what i want. However, i can not see the new value in app.config file. When i open the config file in Debug folder, i only see that:

    <setting name="MyDate" serializeAs="String">
        <value>2013-01-08</value>
    </setting>

And surprisingly, When i rerun the application, MyDate parameter is seem to be "2013-01-08 14:00:00" insead of "2013-01-08"! I looked every config file in Debug folder and project folder but i couldn't find any value with "2013-01-08 14:00:00". But MyDate parameter is set to this value on startup.
I want to know where the value of MyDate variable is stored? Which file should i look for?

SOLUTION EDIT: I decided not to use settings file. I will use app.config file insead of settings file inorder to store my application parameters. app.config is not type-safe but it is easier to edit parameters infile. On the other hand, settings file is like a closed box that you can not find the file which it stores the parameter values.

Fer
  • 1,962
  • 7
  • 29
  • 58
  • Are you trying to write the value to the config file? – Brett Allred Jan 08 '13 at 14:01
  • @BrettAllred i want to be able to edit the value of the variable manually too in config file. But When i changed the config file, it doesnt affect the variable value. Whatismore, i can not find the current value of the variable in any config file. – Fer Jan 08 '13 at 14:06

3 Answers3

1

That's because they are stored in the

<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config file.

For example: C:\Users\<User>\AppData\Local\<Company>\<Product>\<Version>\user.config file.

From your code, you may use:

var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

to get the storage location for your local application data.

[UPDATE]

As you mentioned it is a Windows Service application, try searching the following path:

c:\windows\system32\config\systemprofile\AppData\Local\

Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78
  • i couldn't find C:\Users\\AppData\Local\\\\user.config file path. I looked at Document and Settings folder "Local Setting/Application Data" but there is no file with my application's name. – Fer Jan 08 '13 at 14:13
  • Can you see the company name from your project when you go to: `%APPDATA%`? – Alex Filipovici Jan 08 '13 at 14:16
  • My company name of my service application is empty. [assembly: AssemblyCompany("")]. So i can not see my company name at %APPDATA% folder. What should i do to see the file? – Fer Jan 08 '13 at 14:22
  • Just ignore the `` part of the path, use `\__\\user.config` (i.e. `C:\Users\\AppData\Local\\\user.config`) – Alex Filipovici Jan 08 '13 at 14:44
  • It is not there either. i started file search. Windows is searching for user.config files. By the way, why doesnt this value be stored in myapplication.exe.config file? – Fer Jan 08 '13 at 15:08
  • @Edwin de Koning Windows couldn't find any user.config file. My application is a windows service application. Is that why there is no user.config file for that application? – Fer Jan 08 '13 at 15:29
  • i have already tried that. There are no folder named "Local" in "systemprofile\AppData" folder. There is "Local Settings" folder and i looked that folder too. But there is not any file related to my service application. Althought i found that configuration file which i need, i have to look for a complex path everytime i need to check that file. So i think i should consider using App.config file insead of App.Settings file. Settings file is headache when you want to edit it manually with notepad. – Fer Jan 08 '13 at 15:56
1

The settings with user scope are not actually stored in your app.config, but in a file named user.config. The location of this file is determined by the System.Windows.Forms.Application.LocalUserAppDataPath property. See here for more details on the architecture.

You can also change this location if you want to, see this answer for more details.

Community
  • 1
  • 1
Edwin de Koning
  • 14,209
  • 7
  • 56
  • 74
  • How can i get this file path. I dont use System.Windows.Form because my application is a service application. – Fer Jan 08 '13 at 14:12
  • @Fer Hmmm.. How about c:\windows\system32\config\systemprofile\AppData\Local\ ? – Edwin de Koning Jan 08 '13 at 14:46
  • it is not there neither. I started a file search of "user.config". It seems it will take long time. By the way, why doesnt this value be stored in myapplication.exe.config file? – Fer Jan 08 '13 at 15:01
  • @Fer The value in your in exe.config is essentially a default value, in case your settings file should go missing. – Edwin de Koning Jan 08 '13 at 15:40
0

Everything is OK until now. MyDate parameter is set to what i want. However, i can not see the new value in app.config file.

Here you are doing a misunderstanding with App.config file. the app.config file is your solution file which is a part of your coding / design time. this should not be changed when you run your application either in debug mode or in release mode. what exactly happening is. this one having your default settings. for your App.

say you run your application in debug mode and this will generate output into Bin/ Debug folder which should be having myapplication.exe.config. you need to see this file instead of app.config. what so ever you changed are get changed into myapplication.exe.config. file not in app.config.

JSJ
  • 5,653
  • 3
  • 25
  • 32
  • Thank you for your answer but note that i tried editing myapplication.exe.config file too and it doesnt change the value of my variable neither. – Fer Jan 08 '13 at 14:17