Click to Rate and Give Feedback
MSDN
MSDN Library
Collapse All/Expand All Collapse All
.NET Framework Class Library for Silverlight
FileDialogFileInfo..::.OpenRead Method

Creates a read-only Stream.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Visual Basic (Declaration)
Public Function OpenRead As Stream
Visual Basic (Usage)
Dim instance As FileDialogFileInfo
Dim returnValue As Stream

returnValue = instance.OpenRead()
C#
public Stream OpenRead()
Visual C++
public:
Stream^ OpenRead()
JScript
public function OpenRead() : Stream

Return Value

Type: System.IO..::.Stream

A new read-only Stream object.

The following example shows how to open a file, read the first line, and write the line to a TextBox. For a full code listing, see How to: Use the Open File Dialog Box.

C#
if (openFileDialog1.ShowDialog() == true)
{
    // Open the selected file to read.
    System.IO.Stream fileStream = openFileDialog1.SelectedFile.OpenRead();

    using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
    {
        // Read the first line from the file and write it the textbox.
        tbResults.Text = reader.ReadLine();
    }
    fileStream.Close();
}
Visual Basic
If (openFileDialog1.ShowDialog = True) Then
    'Open the selected file to read.
    Dim fileStream As System.IO.Stream = openFileDialog1.SelectedFile.OpenRead

    Using reader As New System.IO.StreamReader(fileStream)
        ' Read the first line from the file and write it to the text box.
        tbResults.Text = reader.ReadLine
    End Using
    fileStream.Close()
End If
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker