How to solve the problem of Permission denied while reading a file from UWP application?

后端 未结 3 414
梦如初夏
梦如初夏 2021-01-27 11:21

I am trying to reading a .txt file of C or D drive in a UWP application. It is ok, when I declare the local variable for file name in assets. But it\'s filed to read file from o

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 11:44

    You do not have permission to access the file from your C or D Drive. To do So

    1. You need to copy the file to Project folder (Drag and Drop it your Project)

    2. Then you can use this code to access file

    Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("sample.txt");

    if you want to select your file randomly then I would suggest you to use FilePicker Click here

提交回复
热议问题