0

I wan't to create a photo uploading method for my uwp app but there is no way to do it because I can't use FileOpenPicker or any of the other pickers! It cannot find FileOpenPicker, even if declared like Windows.Storage.Pickers.FileOpenPicker(); It complains about the type or namespace Windows not being found. Even when I put using Windows.Storage.Pickers; at the top of the file I have installed NuGet UwpDesktop-Updated to no avail. This is strange because I have been googling for days without finding anyone else with my issue!

Are there any other ways to upload a photo in uwp with c# .net core?

using System;
using System.Windows.Controls;
using Image.ViewModels;
namespace Image.Views
{
    public partial class MainPage : Page
    {
        public MainPage(MainViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;
        }

        private async void Clicked(object sender, EventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                // Application now has read/write access to the picked file
                this.textBlock.Text = "Picked photo: " + file.Name;
            }
            else
            {
                this.textBlock.Text = "Operation cancelled.";
            }
        }
    }
}

chidu
  • 11
  • 1
  • Could you please describe in detail how you created the project? Is the creation process the same as in [this document](https://learn.microsoft.com/en-us/windows/uwp/get-started/create-a-hello-world-app-xaml-universal#step-1-create-a-new-project-in-visual-studio)? In addition, you could check whether your Windows 10 SDK is installed correctly with Visual Studio Installer. – dear_vv Jan 25 '21 at 09:01
  • thanks for the reply! I created a windows template studio (universal studio), then chose mvvm basic instead of codebehind – chidu Jan 26 '21 at 12:56
  • Is your question solved? Do you have any other concerns? – dear_vv Jan 27 '21 at 02:06
  • nope, I just gave up. nothing i could find except come to the realisation that uwp is useless and definitely not for the future – chidu Jan 30 '21 at 14:55
  • Logically, there is nothing wrong with your code. Could you please provide us a [mcve] by OneDrive or GitHub for testing? – dear_vv Feb 01 '21 at 08:07

1 Answers1

0

For desktop apps, you need to use the IInitializeWithWindow interface. Or you could just use the pickers built-in to WPF.

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • thank you for taking the time to reply and helping a java refugee in the weird world of windows programming – chidu Jan 26 '21 at 11:52