The version that the user settings were previously updagraded from
Syntax
Visual Basic (Declaration) | |
---|
Public Property UpgradedVersion As String |
C# | |
---|
public string UpgradedVersion {get; set;} |
Example
Library/Library.Test/TestUserSettings.cs
C# | Copy Code |
---|
UserSettingsSection settings;
Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.IsNull(cfg.GetSection("userSettings"));
settings = UserSettingsSection.UserSettingsFrom(cfg);
settings["a"] = "b";
string origPath = cfg.FilePath;
string dir = Path.GetDirectoryName(cfg.FilePath);
string version = Path.GetFileName(dir).Trim('\\');
dir = dir.TrimEnd('\\') + "1";
Directory.CreateDirectory(dir);
cfg.SaveAs(Path.Combine(dir, Path.GetFileName(origPath)));
File.Delete(origPath);
ConfigurationManager.RefreshSection("userSettings");
cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Assert.IsNull(cfg.GetSection("userSettings"));
settings = UserSettingsSection.UserSettingsFrom(cfg);
Assert.AreEqual("b", settings["a"]);
Assert.AreEqual(version + "1", settings.OriginalVersion);
Assert.AreEqual(version + "1", settings.UpgradedVersion);
string date = DateTime.Now.ToString("yyyy-MM-dd");
Assert.AreEqual(date, settings.UpgradedDate.Substring(0, date.Length)); |
VB.NET | Copy Code |
---|
Dim settings As UserSettingsSection
Dim cfg As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
Assert.IsNull(cfg.GetSection("userSettings"))
settings = UserSettingsSection.UserSettingsFrom(cfg)
settings("a") = "b"
Dim origPath As String = cfg.FilePath
Dim dir As String = Path.GetDirectoryName(cfg.FilePath)
Dim version As String = Path.GetFileName(dir).Trim("\"C)
dir = dir.TrimEnd("\"C) + "1"
Directory.CreateDirectory(dir)
cfg.SaveAs(Path.Combine(dir, Path.GetFileName(origPath)))
File.Delete(origPath)
ConfigurationManager.RefreshSection("userSettings")
cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
Assert.IsNull(cfg.GetSection("userSettings"))
settings = UserSettingsSection.UserSettingsFrom(cfg)
Assert.AreEqual("b", settings("a"))
Assert.AreEqual(version + "1", settings.OriginalVersion)
Assert.AreEqual(version + "1", settings.UpgradedVersion)
Dim [date] As String = DateTime.Now.ToString("yyyy-MM-dd")
Assert.AreEqual([date], settings.UpgradedDate.Substring(0, [date].Length)) |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also