簡體   English   中英

如何獲取當前用戶的我的應用程序設置文件夾路徑?

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

當我使用代碼

Properties.Settings.Default.Save();

保存我的設置,將文件寫入該路徑

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

喜歡

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

如何獲取“應用程序版本”文件夾的路徑,以便可以向其中寫入其他內容?

我正在使用.Net Framework 4.6.2和Visual Studio 2017。

您應該能夠像這樣檢索文件路徑:

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

若要進行此工作,您需要添加對System.Configuration.dll引用(右鍵單擊WPF項目,選擇“ 添加” ,“ 引用...”,然后在“程序集/框架”頁面中選中“ System.Configuration ”旁邊的框。

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

這將返回到AppData的字符串。 只需將文件路徑的其余部分添加到其末尾即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM