In vb you could use SaveSetting and Getsetting which put stuff in the
registery..
Cheers
Andy
(first, look up System.Configuration.AppSettingsReader in MSDN.) Then,
1. If you want to save properties of controls at design time and have them
recalled later, most components have a 'DynamicProperties' property that you
can access. Just check the property you want saved and the program does the
rest for you.
2. If you want to do it at run time, here is some sample code (and this is
also what the design time stuff translates to):
System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();
this.oleDbConnection1.ConnectionString =
((string)(configurationAppSettings.GetValue("oleDbConnection1.ConnectionStri
ng", typeof(string))));
This example reads the value of a key called
"oleDbConnection1.ConnectionString" in your application settings file.
Both these methods write to an app.config XML file in your project directory
which you can distribute with your app.
HTH,
Stacy
"Andrew" <an...@dunn-line.com> wrote in message
news:Ol2z2$B#BHA.2040@tkmsftngp04...
1) Create a Hashtable to store your settings:
Hashtable settings = new Hashtable();
settings["UserName"] = "SomeValue";
settings["Preference1"] = SomeOtherValue;
2) Use IsolatedStorage and formatters to save the values:
private void SaveOptions(Hashtable values)
{
IsolatedStorageFile isoFile =
System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope.
Assembly | IsolatedStorageScope.User, null, null);
IsolatedStorageFileStream stream = new
IsolatedStorageFileStream("mysettings.dat", System.IO.FileMode.Truncate);
System.Runtime.Serialization.IFormatter formatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(stream, values);
stream.Close();
isoFile.Close();
}
3) Use the IsoStore to read those options back in:
private Hashtable LoadOptions()
{
IsolatedStorageFile isoFile =
System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope.
Assembly | IsolatedStorageScope.User, null, null);
IsolatedStorageFileStream stream = new
IsolatedStorageFileStream("mysettings.dat",
System.IO.FileMode.OpenOrCreate);
Hashtable setttings = null;
System.Runtime.Serialization.IFormatter formatter = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
if (stream != null && stream.Length > 0)
{
try
{
settings = (Hashtable)formatter.Deserialize(stream);
}
catch
{
}
}
if (settings == null) return new Hashtable();
stream.Close();
isoFile.Close();
return settings;
}
--
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
"Stacy" <sod...@poboxnospam.com> wrote in message
news:envsu8C#BHA.2040@tkmsftngp05...
Is there a benefit to using this, as opposed to using app.config? (I'm
somewhat slow, so I just discovered app.config yesterday and it seems on
topic to me :-))
Tom
--
Regards
Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
"Tom" <n...@spam.plz> wrote in message news:uAXZh$w#BHA.1984@tkmsftngp04...