Problems with IsolatedStorage read/write

  • Thread starter Thread starter Diana L
  • Start date Start date
D

Diana L

Hi:

I'm trying to get this isolated storage snippet to work. It's trying to
write a few lines, then trying to read them and print them out to the
browser.

The browser prints the "Writing..." lines, and the "End of job" line, but no
"Reading" lines.

I've tried to debug it a bit, and the reader.Peek() value is -1 prior to the
first reader.ReadLine() attempt.

Anyone have any ideas? I'm on VS 2003 & .Net 1.1

Here's the code:

private void Page_Load(object sender, System.EventArgs e)

{

IsolatedStorageFileStream stream = new IsolatedStorageFileStream

("colors.txt",FileMode.Create,FileAccess.ReadWrite);

StreamWriter writer = new StreamWriter(stream);

string[] data = { "red", "orange", "yellow", "green", "blue", "indigo" };

for (int i=0; i<data.Length; i++)

{

writer.WriteLine(data);

Response.Write("Writing: " + data + "<br>");

}

stream.Seek(0,SeekOrigin.Begin);

StreamReader reader = new StreamReader(stream);

while (reader.Peek() > -1)

{

Response.Write("Reading: " + reader.ReadLine() + "<br/>");

}

reader.Close();

Response.Write("Normal eoj.");

}
 
Hi Diana:

You'll want to make sure you close the writer stream before you start
trying to read - that should help.

Also - are you sure you want to use isolated storage on the sever?
It's generally more useful on the client side.

HTH,
 
Scott Allen said:
You'll want to make sure you close the writer stream before you start
trying to read - that should help.

Thanks, I closed the writer stream (which also closes the
IsolatedStorageStream), made a new instance of the isolated storage stream,
and it worked fine.

-- Diana
 
Back
Top