简体   繁体   中英

Can't find Win32 assembly for OpenfileDialog in WPF Framework 4.5.2

I try to code an Open/Save File Dialog in my WPF project on .NET4.5.2. I found solutions based on Win32.OpenFileDialog.

I use Win8.1(x64) and i can't find any Win32 entry in the assemblies of my Visual Studio 2015 Community.

Is there a place i could download an archive ? How could i do to manage my Open/Save Dialog an other way ?

I believe it's in the PresentationFramework assembly:

namespace Microsoft.Win32
{
//
// Summary:
//     Represents a common dialog box that allows a user to specify a filename for one
//     or more files to open.
public sealed class OpenFileDialog : FileDialog
{
    //
    // Summary:
    //     Initializes a new instance of the Microsoft.Win32.OpenFileDialog class.
    [SecurityCritical]
    public OpenFileDialog();

    //
    // Summary:
    //     Gets or sets an option indicating whether Microsoft.Win32.OpenFileDialog allows
    //     users to select multiple files.
    //
    // Returns:
    //     true if multiple selections are allowed; otherwise, false. The default is false.
    public bool Multiselect { get; set; }
    //
    // Summary:
    //     Gets or sets a value indicating whether the read-only check box displayed by
    //     Microsoft.Win32.OpenFileDialog is selected.
    //
    // Returns:
    //     true if the checkbox is selected; otherwise, false. The default is false.
    public bool ReadOnlyChecked { get; set; }
    //
    // Summary:
    //     Gets or sets a value indicating whether Microsoft.Win32.OpenFileDialog contains
    //     a read-only check box.
    //
    // Returns:
    //     true if the checkbox is displayed; otherwise, false. The default is false.
    public bool ShowReadOnly { get; set; }

    //
    // Summary:
    //     Opens a read-only stream for the file that is selected by the user using Microsoft.Win32.OpenFileDialog.
    //
    // Returns:
    //     A new System.IO.Stream that contains the selected file.
    //
    // Exceptions:
    //   T:System.InvalidOperationException:
    //     No files were selected in the dialog.
    [SecurityCritical]
    public Stream OpenFile();
    //
    // Summary:
    //     Creates an array that contains one read-only stream for each file selected by
    //     the user using Microsoft.Win32.OpenFileDialog.
    //
    // Returns:
    //     An array of multiple new System.IO.Stream objects that contain the selected files.
    //
    // Exceptions:
    //   T:System.InvalidOperationException:
    //     No files were selected in the dialog.
    [SecurityCritical]
    public Stream[] OpenFiles();
    //
    // Summary:
    //     Resets all Microsoft.Win32.OpenFileDialog properties to their default values.
    [SecurityCritical]
    public override void Reset();
    [SecurityCritical]
    [SecurityTreatAsSafe]
    protected override void CheckPermissionsToShowDialog();
}
}

If you need a better dialog for directory selection, you need a Microsoft.WindowsAPICodePack Nuget package:

using Microsoft.WindowsAPICodePack.Dialogs;
using System.IO;
// ....
       var browserDialog = new CommonOpenFileDialog();
        browserDialog.IsFolderPicker = true;
        browserDialog.Title = Title;
// ---

You need to add a reference in your project to the PresentationFramework.dll

Then you can simply use:

private Microsoft.Win32.SaveFileDialog saveDialog = new SaveFileDialog();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM