New to Telerik UI for WPF? Download free 30-day trial

Events

This article lists the events specific to all of the RadFileDialog controls.

  • PreviewClosed: This event occurs when the dialog is closing. The event arguments are of type WindowPreviewClosedEventArgs. You can use the arguments to cancel the event.

    Example 1: Cancel dialog closing

        private void OnFileDialogPreviewClosed(object sender, WindowPreviewClosedEventArgs e) 
        { 
            e.Cancel = true; 
        } 
    
  • Closed: This event occurs when the dialog is closed. The event arguments are of type WindowClosedEventArgs.

  • ExceptionRaised: This event occurs when an exception is raised. This event could be raised in different occasions, for example - if the selected folder cannot be accessed or if the file path is too long, or when there is an error while searching, etc.

    Example 2: Showing an alert when an error appears

        private void OnFileDialogExceptionRaised(object sender, FileBrowserExceptionRaisedEventArgs e) 
        { 
            MessageBox.Show(e.Exception.Message); 
        } 
    
  • DirectoryRequesting: This event can be used to filter the navigation RadTreeView and RadBreadcrumb or any Custom Places that are added. The following example demonstrates how you can filter out the "D:\" and "K:\" directories:

    Example 3: Filtering the D and K directories

        private void OnFileDialogDirectoryRequesting(object sender, Telerik.Windows.Controls.FileDialogs.DirectoryRequestingEventArgs e) 
        { 
            if (e.Directory.FullName.StartsWith("D:\\") || e.Directory.FullName.StartsWith("K:\\")) 
            { 
                e.Cancel = true; 
            } 
        } 
    

    If the InitialDirectory of the RadFileDialog is filtered out as in Example 3, the current directory on load will be the default one.

    Figure 1: Unfiltered Directories

    WPF RadFileDialogs Unfiltered Directories

    Figure 2: Filtered Directories Based on Example 3

    WPF RadFileDialogs Filtered Directories Based on Example 3

  • DirectoryNavigating: This event occurs when the current folder is about to change. You can use it to execute an additional action or to cancel the navigation.

    Example 4: Disable navigation to the Program Files folder

        private void OnFileDialogDirectoryNavigating(object sender, Telerik.Windows.Controls.FileDialogs.DirectoryNavigatingEventArgs e) 
        { 
            if (e.DirectoryPath == "C:\\Program Files") 
            { 
                e.Cancel = true; 
            } 
        } 
    
  • ShellContextMenuOpening: This event occurs when the context menu is about to open. You can use it to cancel the menu opening or to add/remove options from the short menu (the one opened when the cursor is on an empty space in the explorer).

    Example 5: Canceling context menu opening and adding only New Folder and Paste options in the short menu

        private void OnFileDialogShellContextMenuOpening(object sender, Telerik.Windows.Controls.FileDialogs.ContextMenuOpeningEventArgs e) 
        { 
            if (e.SelectedFiles.Count > 0 && e.SelectedFiles[0].Path == "C:\\Program Files") 
            { 
                e.Cancel = true; 
            } 
            else 
            { 
                e.ShortContextMenuOptions = ShortContextMenuOptions.Paste | ShortContextMenuOptions.NewFolder; 
            } 
        } 
    

    Additional feature of the ContextMenuOpeningEventArgs provided with the ShellContextMenuOpening event handler is the IsOpeningOnEmptySpace property. You can use this to determine whether the mouse clicked on a file/folder or on empty space in the files list.

    Example 6: Checking if the click was on an empty space

        private void OnFileDialogShellContextMenuOpening(object sender, Telerik.Windows.Controls.FileDialogs.ContextMenuOpeningEventArgs e) 
        { 
            if (e.IsOpeningOnEmptySpace) 
                { 
                          // do something 
                    } 
        } 
    
  • Renaming: This event occurs when a file or a folder is about to be renamed. You can use it to prevent certain files or folders from having their name changed.

    The event arguments will be of the type RenamingEventArgs that exposes the following properties:

    • Cancel: Boolean property that will indicate if a renaming operation will be performed or not.
    • FileInfo: Property of the type FileSystemInfoWrapper. This property contains the FileSystemInfoWrapper object for the file system information that will be renamed.

    This event will occur only when the CanUserRename property is set to True.

    Example 7: Cancel the renaming operation for certain a file/directory

        private void OnFileDialogRenaming(object sender, Telerik.Windows.Controls.FileDialogs.RenamingEventArgs e) 
        { 
            if (e.FileInfo.Path.StartsWith("C:\Windows") 
            { 
                e.Cancel = true; 
            } 
        } 
    

    See Also

  • Getting Started
  • RadOpenFileDialog
  • RadOpenFolderDialog
  • RadSaveFileDialog
In this article