StreamReader.ReadToEnd Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Updated: December 2010
When it is called by trusted applications, reads the stream from the current position to the end of the stream.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overrides Function ReadToEnd As String
public override string ReadToEnd()
Return Value
Type: System.String
The rest of the stream as a string, from the current position to the end. If the current position is at the end of the stream, returns the empty string ("").
Exceptions
Exception | Condition |
---|---|
OutOfMemoryException | There is insufficient memory to allocate a buffer for the returned string. |
IOException | An I/O error occurs. |
Remarks
This method overrides TextReader.ReadToEnd.
ReadToEnd works best when you need to read all the input from the current position to the end of the stream. If more control is needed over how many characters are read from the stream, use the Read(array<Char[], Int32, Int32) method overload, which generally results in better performance.
ReadToEnd assumes that the stream knows when it has reached an end. For interactive protocols in which the server sends data only when you ask for it and does not close the connection, ReadToEnd might block indefinitely because it does not reach an end, and should be avoided.
Note that when using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream. If the size of the buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes).
If the current method throws an OutOfMemoryException, the reader's position in the underlying Stream object is advanced by the number of characters the method was able to read, but the characters already read into the internal ReadLine buffer are discarded. If you manipulate the position of the underlying stream after reading data into the buffer, the position of the underlying stream might not match the position of the internal buffer. To reset the internal buffer, call the DiscardBufferedData method; however, this method slows performance and should be called only when absolutely necessary.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Change History
Date |
History |
Reason |
---|---|---|
December 2010 |
Clarified blocking condition. |
Customer feedback. |