Saving files in Windows Store apps

1.1k views Asked by At

My program handles all the files specified by the user. After preferable to retain the modified file to the directory of the source file. StorageFolder.GetFolderFromPathAsync method returns "Access Denied".
File type associations in the manifest can not be added because after processing the files retain their extension. And what kind of file (with any extension), the user chooses to say impossible. The code in which an 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 file - file that the user specified. I'm trying to create a new folder based on the path of the source file. An error - "Access Denied". To access this folder, i must register the file extensions that I use. It is impossible. Tell me, please, can we get around it as that? Or what can be done in my case?

1

There are 1 answers

2
VasileF On BEST ANSWER

As far as I know, you cannot save a file in the PC unless you proceed with a saving Picker, in the case of a Windows Store App. That is why you might get Access Denied error. Click here for File Access and Permissions.

On the other hand, you can save files always, in a system location dedicated for the app itself, in the ApplicationData.LocalFolder .

You can set additional capabilites to your app so it could acces Removable Devices.

I don't know to be others than these.