2

I have attempted to use the methods on this thread by deadlydog: How to quickly save/load class instance to file

This works in a console application for writing a list of classes to a file. However when I try migrating it to a UWP project I always get "Access to the path ..... is denied"

According to this thread: broadFileSystemAccess UWP I am meant to add broadFileSystemAccess capabilities, which I have done.

However, it also says that I need to use StorageFile APIs, not just classic System.IO API.

I believe the current writing method I am using is utilizing the System.IO API but I do not know how to achieve the same goal using StorageFile APIs.

Could someone please point me in the correct direction?

DavidSNB
  • 171
  • 1
  • 10

2 Answers2

1

You can use the System.IO API, just be sure your code doesn't try to access anything outside its StorageFolder. You can get the StorageFolder path at runtime with this code

Windows.ApplicationModel.Package.Current.InstalledLocation.Path

There is also documentation for how to handle IO in UWP here: https://learn.microsoft.com/en-us/windows/uwp/files/quickstart-reading-and-writing-files

prenone
  • 302
  • 2
  • 20
1

UWP apps are only allowed to write to a small subset of folders on your machine. Using broadFileSystemAccess capability might alleviate it, but it's like using a sledgehammer when you need a screwdriver.

Your application to write data it needs to Windows.Store.ApplicationData.LocalFolder.Path. That folder is writable without any special capabilities.

Sunius
  • 2,789
  • 18
  • 30