FileDialogFileInfo.OpenRead Method

Creates a read-only Stream.

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

Syntax

'Declaration
Public Function OpenRead As Stream
'Usage
Dim instance As FileDialogFileInfo
Dim returnValue As Stream

returnValue = instance.OpenRead()
public Stream OpenRead()
public:
Stream^ OpenRead()
public function OpenRead() : Stream

Return Value

Type: System.IO.Stream

A new read-only Stream object.

Examples

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();
    }
    fileStream.Close();
}
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

See Also

Reference

FileDialogFileInfo Class

FileDialogFileInfo Members

System.Windows.Controls Namespace

Other Resources

How to: Use the Open File Dialog Box