I already found an alternative way to accomplish this (using
ReadBytes), still I'd like to understand why I'm getting and error
reading a text file using the following method. The exception is
returned on the ReadString call.
public string BinaryRead(string fileName)
{
FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
BinaryReader reader = new BinaryReader(stream);
reader.BaseStream.Seek(0, SeekOrigin.Begin);
StringBuilder builder = new StringBuilder();
while(reader.PeekChar() > -1)
{
try
{
// The call to ReadString rises an exception.
builder.Append(reader.ReadString());
}
catch(Exception ex)
{
// Handle exception
}
}
return builder.ToString();
}
Bob Rock