Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.2.dll

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

#Declaration

public Stream OpenFile()

#Returns

Type Description
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.

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)) {
            // ...
        }
    }
}
See Also