Back to Devexpress

XtraOpenFileDialog Class

windowsforms-devexpress-dot-xtraeditors-ebd1cd06.md

latest4.2 KB
Original Source

XtraOpenFileDialog Class

A dialog that allows a user to open a file. Supports DevExpress Skins.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraDialogs.v25.2.dll

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

Declaration

csharp
[DXLicenseWinFormsEditors]
public sealed class XtraOpenFileDialog :
    FileDialogBase,
    IOpenFileDialog,
    IFileDialog,
    ICommonDialog,
    IDisposable
vb
<DXLicenseWinFormsEditors>
Public NotInheritable Class XtraOpenFileDialog
    Inherits FileDialogBase
    Implements IOpenFileDialog,
               IFileDialog,
               ICommonDialog,
               IDisposable

Remarks

Use the inherited ShowDialog() method to display a modal dialog box. The skin of the dialog box matches the skin of the form that invoked that dialog (the owner form). You can also use the ShowDialog(IWin32Window) method overload to explicitly specify the owner form.

The XtraOpenFileDialog supports environment variables (for instance, %WINDIR% and %TEMP%) in the address bar.

To force all DevExpress controls and components to use XtraOpenFileDialogs instead of standard dialogs, enable the WindowsFormsSettings.UseDXDialogs property.

See the following topic on docs.microsoft.com for more information: OpenFileDialog.

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

Inheritance

Object MarshalByRefObject Component CommonDialog XtraCommonDialog FileDialogBase XtraOpenFileDialog

See Also

XtraOpenFileDialog Members

DevExpress.XtraEditors Namespace