0

How i can ask user give me access on files which I could be read. So, I do this only for myself, so I understand, that I can start app from admin name and by idea i will can get access on files. But this UWP. Application, where i can't do this. From this problem, question arises. The question that I asked in the first sentence: how i can ask user give me access on files. On example, this code throw access exception on execute stage:

public static async Task<byte[]> LoadFromPathAsync(string path)
        {
            byte[] buffer = null;
            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                buffer = new byte[stream.Length];
                await stream.ReadAsync(buffer, 0, buffer.Length);
            }
            return buffer;
        }

I'm sorry for my poor knowledge of English, I wrote this text myself

lenkoras
  • 38
  • 8
  • UWP bascially means "App Development". And Apps have to ask (but still may not receive) any single right. Short of their own temporary and storage files, they have no guaranteed access onto anything. | It may not help you here, but UWP is basically just WPF with App support Added. And the next .NET Core will re-add WPF support. So if you like the Style or want to recycle code, but do not need it to be a App Store App, switching to WPF is a possibility. – Christopher Nov 18 '19 at 01:54

2 Answers2

0

This File access permissions will explain you how to get File Access Permission. By the above link you can get permission. Here is a simple code you can use for file operations.

You can use Local storage folder file save operations. Here is how you can access the local state folder

Write to a file

    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
    StorageFile file = await storageFolder.CreateFileAsync("sample", CreationCollisionOption.OpenIfExists);
    await FileIO.WriteTextAsync(file, "some text to write in file");

Read from a file

StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await storageFolder.GetFileAsync("sample");
string text= await FileIO.ReadTextAsync(file);
Noorul
  • 873
  • 2
  • 9
  • 26
0

There is a way you can ask for more file system access, which is called BroadFileSystemAccess.

You can get the details in this thread.

Noorul
  • 873
  • 2
  • 9
  • 26