2

There is literally no working API available which allows users to simply click a button in my app and be presented with a dialog box which would allow them to select files. Am I missing something here?

LeBrown Jones
  • 887
  • 6
  • 17

2 Answers2

2

Again the only answer is that you are too much of an early bird.

The file picker is a big problem because it's highly intervowen into the sandboxing model. Its on the roadmap for 1.0 release together with the application activation (start from command line, start menu, clicking url, service etc.) and non sandboxed/non MSIX packaging.

Lothar
  • 12,537
  • 6
  • 72
  • 121
0

There is COM interface called IWindowNative to get the HWND of a Window object. Unfortunately, the C#/WinRT projections need some improvements (already in-place for the Preview 2) to enable consume the COM Interfaced as it was spec'ed.

[ComImport]
        [Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IInitializeWithWindow
        {
            void Initialize(IntPtr hwnd);
        }
        [ComImport]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        [Guid("EECDBF0E-BAE9-4CB6-A68E-9598E1CB57BB")]
        internal interface IWindowNative
        {
            IntPtr WindowHandle { get; }
        }
            var filePicker = new FileOpenPicker();

            //Get the Window's HWND
            var hwnd = this.As<IWindowNative>().WindowHandle;

            //Make folder Picker work in Win32
            var initializeWithWindow = filePicker.As<IInitializeWithWindow>();
            initializeWithWindow.Initialize(hwnd);

            filePicker.FileTypeFilter.Add("*");

            var folder = await filePicker.PickSingleFileAsync();
Majid Shahabfar
  • 4,010
  • 2
  • 28
  • 36