首页 > 解决方案 > 如何使用 xamarin.forms 创建文件夹以在 iOS 中存储下载的文件

问题描述

我正在尝试下载 pdf 文件并尝试使用 xamarin.forms 从我的应用程序中查看它。我能够在 android 设备中创建路径,但无法在 iPad 上创建路径。我需要创建自定义文件夹并需要下载该目录中的文件。如何实现。

string decoded = System.Text.Encoding.ASCII.GetString(fileBytes);

               byte[] encodedDataAsBytes = DecodeUrlBase64(DataString);

               string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

               string finalPath=Path.Combine(documentsPath, Path.GetFileName(fileFullPath));

               Directory.CreateDirectory(finalPath);

               File.WriteAllBytes(finalPath, encodedDataAsBytes);

标签: iosxamarin.forms

解决方案


删除后一切正常CreateDirectory,以下是对我的代码所做的更改,这些更改按我的预期工作

byte[] encodedDataAsBytes = DecodeUrlBase64(DataString);

                string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

                string finalPath = Path.Combine(documentsPath, Path.GetFileName(fileFullPath));

                File.WriteAllBytes(finalPath, encodedDataAsBytes);

推荐阅读