Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get my app settings folder path for the current user?

Tags:

c#

wpf

When I use the code

Properties.Settings.Default.Save();

to save my settings it write the file to that path

%USERPROFILE%\AppData\Local\MyAppName\MyAppName.exe_Url_SomeWiredCode\TheAppVersionNumber\user.config

like

"C:\Users\Username\AppData\Local\MyApp\MyApp.exe_Url_claumreyuxtgqul2vuc3couyu5tso2n0\1.0.0.0\user.config"

How can I get the path for "the app version" folder so I can write another stuff to it?

I am using .Net Framework 4.6.2 and Visual Studio 2017.

like image 564
ahmedpio Avatar asked Feb 20 '18 08:02

ahmedpio


Video Answer


1 Answers

You should be able to retrieve the file path like this:

var level = ConfigurationUserLevel.PerUserRoamingAndLocal;
var configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(level);
var configurationFilePath = configuration.FilePath

To make this work, you need to add reference to System.Configuration.dll (right-click your WPF project, select Add, Reference... and check the box next to System.Configuration in the Assemblies/Framework page.

like image 56
Martin Zikmund Avatar answered Sep 28 '22 09:09

Martin Zikmund