Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin找不到路径的一部分_C#_Android_File_Xamarin_Io - Fatal编程技术网

C# Xamarin找不到路径的一部分

C# Xamarin找不到路径的一部分,c#,android,file,xamarin,io,C#,Android,File,Xamarin,Io,我正在尝试将位图保存到Android存储中。 我的代码如下所示: var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var filePath = System.IO.Path.Combine(folderPath, "Pictures/profile_picture.png"); var stream = new FileStream(filePath, FileMo

我正在尝试将位图保存到Android存储中。 我的代码如下所示:

var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var filePath = System.IO.Path.Combine(folderPath, "Pictures/profile_picture.png");
var stream = new FileStream(filePath, FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();
但应用程序进入中断模式,并显示:

System.IO.DirectoryNotFoundException:找不到路径的一部分。

感谢您的帮助。 提前感谢Zoedingl。

未创建“图片”目录。因此,您会遇到“找不到路径的一部分”错误。更改代码如下,或者您可以为“图片”创建目录,然后使用相同的代码

var filePath = System.IO.Path.Combine(folderPath, "profile_picture.png");
创建目录的代码

 Directory.CreateDirectory(System.IO.Path.Combine(folderPath, "Pictures"));

@SushiHangover是的,它有。
filePath
的值是多少?@SushiHangover filePath的值是Android/data/com.oedingsoftware.retrogamez/files/Pictures/profile_picture.pngWhen我创建文件夹
picture
(如果文件夹存在,忽略创建文件夹),代码没有错误。请检查屏幕截图@温迪·臧我现在更困惑了。我在代码的另一部分创建文件夹。也许我应该像你一样把它移到那个地方去?文件夹已经存在了,谢谢。@Zoedingl那是什么问题?若文件夹已存在,则不会出现“找不到路径”问题。你能告诉我是什么问题吗。这可能会帮助其他遇到这种问题的人。我得到了正确的错误代码和idk为什么