在我的WPF應用程序,我點擊在Solution Explorer Settings.settings,並用用戶範圍輸入StringCollection變量:Properties.Settings.Default的數據在哪裏保存?
alt text http://i45.tinypic.com/24xdmir.png
在我的app.config我看到它們都保存有:
<userSettings>
<TestSettings.Properties.Settings>
<setting name="Paths" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>one</string>
<string>two</string>
<string>three</string>
<string>four</string>
<string>five</string>
<string>six</string>
<string>seven</string>
</ArrayOfString>
</value>
</setting>
</TestSettings.Properties.Settings>
</userSettings>
然後我運行我的應用程序與THI S碼:
StringCollection paths = Properties.Settings.Default.Paths;
Properties.Settings.Default.Paths.Add("added in code");
Properties.Settings.Default.Save();
foreach (var path in paths)
{
System.Console.WriteLine(path);
}
這給了我這個輸出:
one
two
three
four
five
six
seven
added in code
我再次運行應用程序,這讓我這個輸出:
one
two
three
four
five
six
seven
added in code
added in code
但我看我的app.config再次它仍然有個原始值:
<userSettings>
<TestSettings.Properties.Settings>
<setting name="Paths" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>one</string>
<string>two</string>
<string>three</string>
<string>four</string>
<string>five</string>
<string>six</string>
<string>seven</string>
</ArrayOfString>
</value>
</setting>
</TestSettings.Properties.Settings>
</userSettings>
如果是由應用程序添加的值被保存?
我有同樣的問題。當我保存時,我發現它在AppData \ Local \ xxxx文件夾中得到更新。但是當我啓動應用程序時,它不會從那裏讀取。我如何強制它從那裏讀取? – coolshashi 2015-03-20 02:45:44
@coolshashi,在您描述您觀察加載用戶設置失敗的確切條件時,您最好創建一個新問題。 – 2015-03-20 08:55:44
對於Windows 10,此答案仍然正確,並且適用於WPF和winforms。所以'user.config'的路徑是'<...> \ Users \ \ AppData \ Local \ \ .exe_Url_ <32個隨機字符> \ '。您的應用程序名稱被截斷爲25個字符,可能是最大的? –
2016-07-30 16:10:23