Back to Devexpress

XtraOpenFileDialog.OpenFile() Method

windowsforms-devexpress-dot-xtraeditors-dot-xtraopenfiledialog-70305b3c.md

latest2.7 KB
Original Source

XtraOpenFileDialog.OpenFile() Method

Opens the file specified by the FileName property. The file is opened with read-only permission.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraDialogs.v25.2.dll

NuGet Packages : DevExpress.Win.Dialogs, DevExpress.Win.Navigation

Declaration

csharp
public Stream OpenFile()
vb
Public Function OpenFile As Stream

Returns

TypeDescription
Stream

A Stream that stores the selected read-only file.

|

Remarks

See the OpenFileDialog.OpenFile article to learn more.

Example

The following example demonstrates how to show the XtraOpenFileDialog.

csharp
using System.IO;

private void simpleButtonOpenFileDialog_Click(object sender, EventArgs e) {
    xtraOpenFileDialog1.InitialDirectory = "c:\\";
    xtraOpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

    if(xtraOpenFileDialog1.ShowDialog() == DialogResult.OK) {
        // Get the path of specified file.
        string filePath = xtraOpenFileDialog1.FileName;

        // Read the contents of the file into a stream.
        var fileStream = xtraOpenFileDialog1.OpenFile();
        using(StreamReader reader = new StreamReader(fileStream)) {
            // ...
        }
    }
}
vb
Imports System.IO

Private Sub simpleButtonOpenFileDialog_Click(ByVal sender As Object, ByVal e As EventArgs)
    xtraOpenFileDialog1.InitialDirectory = "c:\"
    xtraOpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

    If xtraOpenFileDialog1.ShowDialog() = DialogResult.OK Then
        ' Get the path of specified file.
        Dim filePath As String = xtraOpenFileDialog1.FileName

        ' Read the contents of the file into a stream.
        Dim fileStream = xtraOpenFileDialog1.OpenFile()
        Using reader As New StreamReader(fileStream)
            ' ...
        End Using
    End If
End Sub

See Also

XtraOpenFileDialog Class

XtraOpenFileDialog Members

DevExpress.XtraEditors Namespace