The Perfectionist
The Perfectionist

Reputation: 57

Upload picture in Assets folder in windows store application

I am developing a windows store application, where I need to upload an image and save it in Assets folder. I am new in C#. Here is my code.

var picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.Desktop;
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            StorageFile file = await picker.PickSingleFileAsync();

            if (file == null) return;
            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
            BitmapImage image = new BitmapImage();
            image.SetSource(stream);
            imageTargetControl.Source = image;
            StorageFolder storageFolder = KnownFolders.DocumentsLibrary; 
            StorageFile copyFile = await file.CopyAsync(storageFolder);

Kindly help me. Thanks

Upvotes: 1

Views: 1333

Answers (1)

Ross Dargan
Ross Dargan

Reputation: 6021

You can't save it into your assets folder as you won't have write permissions there.

You must store it into one of the app data folders (LocalFolder, RoamingFolder, or TemporaryFolder).

If you want to store the file anywhere else you can request additional permission for the application (such as permission to write in the photos library) but if you want to save somewhere that's not a library you must ask the user where via a folderpicker dialog, and it's the users choice.

Upvotes: 2

Related Questions