Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]ViewModels
  [Expand]Commands
  [Expand]Behaviors
  [Collapse]Services
    Getting Started
    Services in ViewModelBase descendants
    Services in POCO objects
    Services in custom ViewModels
    View creation mechanisms
   [Collapse]Predefined Set
    [Expand]Dialog Services
    [Expand]Message Box Services
    [Expand]Document Services
    [Expand]ViewInjectionService
    [Expand]Report Services
     NotificationService
     TaskbarButtonService
     ApplicationJumpListService
     DXSplashScreenService
     DispatcherService
     FrameNavigationService
     LayoutSerializationService
     FolderBrowserDialogService
     OpenFileDialogService
     SaveFileDialogService
     WizardService
     NotifyIconService
    How to create a Custom Service
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

OpenFileDialogService

The OpenFileDialogService is an IOpenFileDialogService implementation that allows you to browse and open files in the File System by using the standard dialog box.

To implement the file browsing functionality in accordance with the MVVM pattern, use the OpenFileDialogService class provided by MVVM Framework.

Using the OpenFileDialogService functionality requires a OpenFileDialogService instance to be attached to a View. You can do this by using the Smart Tag as described in Attaching MVVM Behaviors and Services or manually as shown in the code snippet below.

To show the dialog box, access the attached OpenFileDialogService (a description on how to obtain a service from a View Model is available here: Services in POCO objects and Services in ViewModelBase descendants) and invoke its IOpenFileDialogService.ShowDialog method.

When the shown dialog is closed and the ShowDialog method returns True, you can obtain the selected file in the IOpenFileDialogService.File property. If the OpenFileDialogService.Multiselect feature is enabled and multiple files are selected, use the IOpenFileDialogService.Files property instead.

Note

The OpenFileDialogService uses its own FileInfoWrapper class implementing the IFileInfo interface to represent the selected file(s). This class provides the capabilities of the standard FileInfo to work with objects of the FileStream type.

If you want to enable the user with the ability to select a folder instead of a file, use the FolderBrowserDialogService instead.

Expanded Example

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T300099.

Is this topic helpful?​​​​​​​