S
Scott Roberts
wASP said:Hi,
I'm having a problem with the StreamWriter class in System.IO.
I can generate output to a webpage by attaching a string object to a label,
and viewing it OK on postback, but when I try to write it to a file (appended),
with stream IO, it hangs after about 4,180 bytes.
It goes something like this:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=-=-=-=-=-
class my_class
{ private string logfile_path = @"I:\Virtual Webfolders\CtrlInit\Struct.txt";
private StreamWriter strm_wrtr;
private string dbl_line = "============================<br>";
private void my_fn ()
{ strm_wrtr = File.AppendText(logfile_path);
strm_wrtr.WriteLine(dbl_line);
// more code with WriteLines scattered throughout.
}
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=-=-=-=-=-
After it hangs, the file is locked - I cannot delete it - or change its contents
- until I restart IIS.
Does anyone have any ideas that might help this poor fool out?
I don't see any immediate problems with the code you posted (assuming you
have strm_wrtr.Close() somewhere). Are you sure it just hangs? No
exceptions? Can we see "// more code"?
Does anything at all get written to the file (i.e. once you stop IIS and
view the file is there anything in it)? Could it be a permissions problem
(i.e. the user account under which IIS is running doesn't have permission to
write to that directory)? If this were the case, you would get an exception
as opposed to a "hang", but if you are catching exceptions and not
re-throwing them it could appear to be a "hang". It's difficult to tell
without all of the code.