Back to Devexpress

File and Folder Browsers

windowsforms-403445-controls-and-libraries-messages-notifications-and-dialogs-file-and-folder-browsers.md

latest3.4 KB
Original Source

File and Folder Browsers

  • Sep 16, 2022
  • 2 minutes to read

The DevExpress WinForms installation ships with two options for file and folder browsers:

How to Show XtraSaveFileDialog

The following example demonstrates how to show the XtraSaveFileDialog.

csharp
using System.IO;

private void simpleButtonSaveFileDialog_Click(object sender, EventArgs e) {
    Stream memoStream;
    xtraSaveFileDialog1.Filter = "txt files (*.txt)|*.txt";

    if(xtraSaveFileDialog1.ShowDialog() == DialogResult.OK) {
        if((memoStream = xtraSaveFileDialog1.OpenFile()) != null) {
            // Code to write the stream goes here.

            memoStream.Close();
        }
    }
}
vb
Imports System.IO

Private Sub simpleButtonSaveFileDialog_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim memoStream As Stream
    xtraSaveFileDialog1.Filter = "txt files (*.txt)|*.txt"

    If xtraSaveFileDialog1.ShowDialog() = DialogResult.OK Then
        memoStream = xtraSaveFileDialog1.OpenFile()
        If memoStream IsNot Nothing Then
            ' Code to write the stream goes here.

            memoStream.Close()
        End If
    End If
End Sub

How to Show XtraOpenFileDialog

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