FileDialogFileInfo.OpenRead Method

Creates a read-only Stream.

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


Public Function OpenRead As Stream
Dim instance As FileDialogFileInfo
Dim returnValue As Stream

returnValue = instance.OpenRead()
public Stream OpenRead()
Stream^ OpenRead()
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.

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();
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
End If

See Also


FileDialogFileInfo Class

FileDialogFileInfo Members

System.Windows.Controls Namespace

Other Resources

How to: Use the Open File Dialog Box