Einzelnen Beitrag anzeigen
Alt 17.03.2009, 10:31   #5
Yoghurt
Jr. Member
 
Benutzerbild von Yoghurt
 
Registriert seit: 28.12.2000
Alter: 48
Beiträge: 49


Yoghurt eine Nachricht über Skype™ schicken
Standard

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.
____________________________________
lg Yoghurt

--
Rettet unsere Wälder, esst mehr Biber!
Yoghurt ist offline   Mit Zitat antworten