Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Picker #4710

Open
1 of 3 tasks
Abhi-95 opened this issue Aug 25, 2023 · 0 comments
Open
1 of 3 tasks

File Picker #4710

Abhi-95 opened this issue Aug 25, 2023 · 0 comments
Labels
bug The issue relates to the wizard not working or a problem with the generated code.

Comments

@Abhi-95
Copy link

Abhi-95 commented Aug 25, 2023

Describe the bug

Code : https://github.com/microsoft/WinUI-Gallery/blob/main/WinUIGallery/ControlPages/FilePickerPage.xaml.cs

// Create a file picker
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

// Retrieve the window handle (HWND) of the current WinUI 3 window.
var window = WindowHelper.GetWindowForElement(this);
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);

// Initialize the file picker with the window handle (HWND).
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hWnd);

// Set options for your file picker
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.FileTypeFilter.Add("*");

// Open the picker for the user to pick a file
var file = await openPicker.PickSingleFileAsync();
if (file != null)
{
PickAFileOutputTextBlock.Text = "Picked file: " + file.Name;
}
else
{
PickAFileOutputTextBlock.Text = "Operation cancelled.";

}

Error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Windows.SDK.NET
StackTrace:
at WinRT.Interop.IWindowNativeMethods.get_WindowHandle(Object _obj)
at WinRT.Interop.WindowNative.GetWindowHandle(Object target)
at Orchid.Views.HomePage.<OpenFile_Click>d__4.MoveNext()

What are the step to handle File Picker?

To Reproduce

No response

Additional context

No response

Applies to the following platforms:

  • WinUI
  • WPF
  • UWP

About your setup

No response

@Abhi-95 Abhi-95 added the bug The issue relates to the wizard not working or a problem with the generated code. label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue relates to the wizard not working or a problem with the generated code.
Projects
None yet
Development

No branches or pull requests

1 participant