CSharpTest.Net
OriginalVersion Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.AppConfig Namespace > UserSettingsSection Class : OriginalVersion Property

Glossary Item Box

Describes the version of the application that originally wrote the configuration

Syntax

Visual Basic (Declaration) 
Public Property OriginalVersion As String
C# 
public string OriginalVersion {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.NETCopy 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

Generated with Document! X 2011 by Innovasys