Xamarin:Android:System.UnauthorizedAccessException:创建Excel时拒绝访问路径

时间:2020-06-30 04:22:03

标签: c# android xamarin path

我尝试访问该链接,并且我请求了所有权限,并且尝试了很多链接,但是仍然会发生该错误 这是我的代码:

 public void CreateExcel()
    {
        if (excelFilePath.Equals("") == false)
        {
            try
            {
            if (ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.WriteExternalStorage) == (int)Android.Content.PM.Permission.Granted
                && ContextCompat.CheckSelfPermission(this.Activity, Manifest.Permission.WriteExternalStorage) == (int)Android.Content.PM.Permission.Granted)
            {
                // We have permission, go ahead and use 

                ExcelEngine excelEngine = new ExcelEngine();
                IApplication application = excelEngine.Excel;
                IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
                Stream a = System.IO.File.OpenRead(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath);
                workbook.SaveAs(a);
                workbook.Close();
                a.Dispose();
                }
                catch(Exception ex) { System.Console.WriteLine(ex.Message); }
               }
            }
        }
        else CheckAppPermissions();
    }

编辑 我已经解决了lowercase()函数,但是我不知道为什么?

0 个答案:

没有答案
相关问题