Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Winform Settings file location

Tags:

c#

.net

winforms

When you create suppose C# Winform application and go to project properties there is this tab called settings which allows you to store some variables. so when user closes application and runs it again those values would not be lost. So as I guess somewhere some file is created to store the values declared in settings tab. Does anybody know where this file is located at?

like image 840
Dimitri Avatar asked Nov 22 '25 18:11

Dimitri


1 Answers

If you tried to add settings you wanted to persist, you would have been able to see them in YourApp.exe.config file which is in the same directory where is build output binary.

For settings like this:

enter image description here

...WindowsFormsApplication1.exe.config file (generated by the Visual Studio and placed in the same directory where it output WindowsFormsApplication1.exe) contains settings you added:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="WindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="WindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <userSettings>
        <WindowsFormsApplication1.Properties.Settings>
            <setting name="UserSetting" serializeAs="String">
                <value>UserValue</value>
            </setting>
        </WindowsFormsApplication1.Properties.Settings>
    </userSettings>
    <applicationSettings>
        <WindowsFormsApplication1.Properties.Settings>
            <setting name="AppSetting" serializeAs="String">
                <value>AppValue</value>
            </setting>
        </WindowsFormsApplication1.Properties.Settings>
    </applicationSettings>
</configuration>

From MSDN's Application Settings Architecture:

  • Application-scoped settings can be stored in either the machine.config or app.exe.config files. Machine.config is always read-only, while app.exe.config is restricted by security considerations to read-only for most applications.
  • User-scoped settings can be stored in app.exe.config files, in which case they are treated as static defaults.
  • Non-default user-scoped settings are stored in a new file, user.config

Further down you can see file locations:

The location of the app.exe.config and user.config files will differ based on how the application is installed. For a Windows Forms-based application copied onto the local computer, app.exe.config will reside in the same directory as the base directory of the application's main executable file, and user.config will reside in the location specified by the Application.LocalUserAppDataPath property.

like image 162
Bojan Komazec Avatar answered Nov 24 '25 07:11

Bojan Komazec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!