Share via


OpenFileDialog.ShowDialog Method (Window)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Displays an OpenFileDialog that is modal to the specified window.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Function ShowDialog ( _
    owner As Window _
) As Nullable(Of Boolean)
public Nullable<bool> ShowDialog(
    Window owner
)

Parameters

Return Value

Type: System.Nullable<Boolean>
true if the user clicked OK; false if the user clicked Cancel or closed the dialog box.

Exceptions

Exception Condition
InvalidOperationException

Silverlight was unable to display the dialog box.

SecurityException

Active Scripting in Internet Explorer is disabled.

-or-

The call to the ShowDialog method was not made from user-initiated code or too much time passed between user-initiation and the display of the dialog.

Remarks

The ShowDialog method can only be used with trusted out-of-browser applications. If you call ShowDialog in an application that is not trusted, but is an out-of-browser application, the dialog will be modal to the main window.

Use the return value of the ShowDialog method to determine whether the user selected a file.

The ShowDialog method can only be called from user-initiated code, such as a button Click event. If ShowDialog is called from code that is not user-initiated, such as a PageLoaded event, a SecurityException is thrown. In addition, there is a limit on the time allowed between when the user initiates the dialog and when the dialog is shown. If the time limit between these actions is exceeded, an exception will occur.

If you attempt to show the dialog box from KeyDown event handlers and other synchronous calls to application code, such as LayoutUpdated or SizeChanged event handlers, an exception will be thrown. An exception will not be thrown when the application is hosted in Internet Explorer, running in protected mode.

The Silverlight plug-in does not support OpenFileDialog in full-screen mode. In most cases, displaying this dialog box in full-screen mode will cause the plug-in to revert to embedded mode. To avoid issues on some browsers, you should exit full-screen mode before using this class. For more information, see Full-Screen Support.

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.