Hi,
also ich hab mir angewöhnt Settings, die ich auch in Datenbanken ablegen möchte gleich als DataTable zu erzeugen. DataTables kann man leicht serialisieren und als XML Datei wegschreiben. Kleines Beispiel (DataTable mit Ignore Values im Isolated User Store speichern und wieder laden)...
Settings erzeugen und speichern...
Code:
// Create DataTable for Settings
DataTable mySettings = newDataTable("Ignore");
mySettings.Columns.Add("Value", typeof(System.Int32));
// Add Test Settings
mySettings.Rows.Add(newobject[1] { 1 });
mySettings.Rows.Add(newobject[1] { 2 });
mySettings.Rows.Add(newobject[1] { 3 });
// Create Isolated Storage Stream
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User
| IsolatedStorageScope.Assembly, null, null);
IsolatedStorageFileStream myIsolatedStream =
newIsolatedStorageFileStream("MyConfigFile.xml", FileMode.Create, isoStore);
// Write to Isolated Storage
mySettings.WriteXml(myIsolatedStream, XmlWriteMode.WriteSchema);
// Close Stores
myIsolatedStream.Close();
isoStore.Close();
Settings laden und anzeigen...
Code:
// Create Isolated Storage Stream
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User
| IsolatedStorageScope.Assembly, null, null);
try
{
// Open Config File
IsolatedStorageFileStream myIsolatedStream =
newIsolatedStorageFileStream("MyConfigFile.xml", FileMode.Open, isoStore);
// Create Settings Table
DataTable mySettings = newDataTable("Ignore");
mySettings.ReadXml(myIsolatedStream);
// Read 1. Ignore Setting
MessageBox.Show("First Ignore Value is " + mySettings.Rows[0]["Value"].ToString());
myIsolatedStream.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error. File not found or error reading config file. " + ex.ToString());
}
Kann dir das kleine Test Projekt auch schicken wenn du willst.