faild to write to usb sd card in .net android

mc 5,426 Reputation points
2025-06-03T14:57:08.28+00:00

I am using .net android and I want to write to the usb sd card.

var sm = (Android.OS.Storage.StorageManager)GetSystemService(Android.Content.Context.StorageService);
if (sm == null)
{
    return;
}
var path = sm.StorageVolumes?.FirstOrDefault(x => x.IsRemovable)?.Directory;
if (path == null)
{
    return;
}
var _path = path.AbsolutePath;
var f = new Java.IO.File(o);
var f1 = new Java.IO.File(_path + "/" + f.Name);
var inf = new Java.IO.FileInputStream(f);
f1.CreateNewFile();
var ino = new Java.IO.FileOutputStream(f1);
var buffer = new byte[3096];
int length;
while ((length = inf.Read(buffer)) > 0)
{
    ino.Write(buffer, 0, length);
}

but failed

how to do it?

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.