How to read & write file in isolation storage in c#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.IO.IsolatedStorage; using System.Diagnostics; namespace Program { //Variable string FullLine; const string ISOLATED_FILE_NAME = "Setting.txt"; IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null); private void ISOStorageUse_Load(object sender, EventArgs e) { cbYesNo.Text = "No"; ddlStandard.SelectedIndex = 0; #region Get Data IsolatedStorageFileStream iStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore); StreamReader reader = new StreamReader(iStream); FullLine = reader.ReadToEnd(); reader.Close(); #endregion Get Data #region Apply Value string SplitPart = FullLine.Replace("\r\n", ","); string[] Parts = SplitPart.Split(','); if (SplitPart == "") return; dtpDate.Value = Convert.ToDateTime(Parts[0]); tbName.Text = Parts[1]; ddlStandard.SelectedIndex = Convert.ToInt32(Parts[2]); cbYesNo.Checked = Convert.ToBoolean(Parts[3]); #endregion Apply Value } // Form Closing Event private void ISOStorageUse_FormClosing(object sender, FormClosingEventArgs e) { // Write some text into the file in isolated storage. IsolatedStorageFileStream oStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore); StreamWriter writer = new StreamWriter(oStream); writer.WriteLine(dtpDate.Value); writer.WriteLine(tbName.Text); writer.WriteLine(ddlStandard.SelectedIndex); writer.WriteLine(cbYesNo.Checked); writer.Close(); } }
No comments :
Post a Comment