Search code examples
xamarinxamarin.androidxamarin.essentials

Xamarin.Essentials; FilePicker; Save a new file


Using FilePicker one can open an existing file:

         FileResult file = await FilePicker.PickAsync();
         TextView textview = FindViewById<TextView>(Resource.Id.textview);
         string path = file.FullPath;
         var handle = File.Open(path, FileMode.OpenOrCreate);
         byte[] data = new byte[10];
         handle.Read(data, 0, 10);

Is there a similar way for saving a new file?


Solution

  • For now, the FilePicker plugin is only designed to pick existing files.

    On Android and iOS, you could not do that. But on UWP, you could use the FileSavePicker.

    Xamarin: https://learn.microsoft.com/en-us/xamarin/essentials/file-picker?tabs=android

    UWP: https://learn.microsoft.com/en-us/windows/uwp/files/quickstart-save-a-file-with-a-picker