Saving files in Windows Store apps

My program processes all files specified by the user. After the preferred save the modified file to the directory of the source file. StorageFolder.GetFolderFromPathAsync returns "Access Denied" .
It is not possible to add file type associations to the manifest because the files retain their extension after processing. And which file (with any extension) the user chooses to say impossible. The code in which the error occurs.

  internal async static void SetFile(List<byte> byteArray , StorageFile file) { try { string path = Path.GetDirectoryName(file.Path); StorageFolder newFolder = await StorageFolder.GetFolderFromPathAsync(path); StorageFile newFile = await newFolder.CreateFileAsync(string.Format(@"crt{0}", Path.GetFileName(file.Name)), CreationCollisionOption.FailIfExists); Stream stream = await file.OpenStreamForWriteAsync(); BinaryWriter writer = new BinaryWriter(stream); writer.Write(byteArray); writer.Flush(); } catch (Exception ex) { throw ex; } } 

StorageFile - The file specified by the user. I am trying to create a new folder based on the path of the source file. Error - "Access Denied." In order to access this folder, I have to register the file extensions that I use. It's impossible. Please tell me can we get around this? Or what can be done in my case?

+4
source share
1 answer

As far as I know, you cannot save the file to your PC unless you start using Save Picker in the case of the Windows Store application. This is why you may get Access Denied error. Click here for File Access and Permissions.

On the other hand, you can always save files in the system location intended for the application itself, in ApplicationData.LocalFolder .

You can install additional features for your application so that it can access Removable Devices.

I do not know what others are.

+1
source

Source: https://habr.com/ru/post/1496640/


All Articles