ASP.Net/File Directory/IsolatedStorageFileStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:51, 26 мая 2010
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>
Using IsolatedStorageFileStream
<%@ Page %>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
System.IO.IsolatedStorage.IsolatedStorageFileStream stream = null;
System.IO.StreamWriter writer = null;
String data = "The data you want to store";
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();
}
}
</script>