StreamWriter from IsolatedStorageFileStream : IsolatedStorageFileStream « File Directory « ASP.Net






StreamWriter from IsolatedStorageFileStream

<%@ Page %>
<script runat="server" language="C#">
void Page_Load(Object sender, EventArgs e)
{
  System.IO.IsolatedStorage.IsolatedStorageFileStream stream = null;
  System.IO.StreamReader reader = null;
  System.IO.StreamWriter writer = null;
  String data = "The data";

  try
  {
    stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream("Data.txt", System.IO.FileMode.OpenOrCreate);
    writer = new System.IO.StreamWriter(stream);

    writer.WriteLine(data);
  }
  catch (Exception ex)
  {
    Response.Write(ex.ToString());
  }
  finally
  {
    writer.Close();
    stream.Close();
  }

  try {
    stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream("Data.txt", System.IO.FileMode.OpenOrCreate);
    reader = new System.IO.StreamReader(stream);
      
    while ( reader.Peek() > -1 )
    {
      Response.Write(Server.HtmlEncode(reader.ReadLine()) + "<br>");
    }
  } catch (Exception exc) {
    Response.Write(exc.ToString());
  } finally {
    stream.Close();
    reader.Close();
    
  }
}
</script>

 








Related examples in the same category

1.Using IsolatedStorageFileStream