0

I have the following code, but I need to allow the user to choose where they want the .csv file saved.

    public void ExportData()
    {
        Init();

        TableQuery<Record> Records = conn.Table<Record>();

        List<Record> records = Records.ToList();

        string csvFilePath = System.IO.Path.Combine(FileSystem.AppDataDirectory, "export.csv");

        using (StreamWriter writer = new StreamWriter(csvFilePath))
        {
            // Write the column headers to the CSV file
            // writer.WriteLine("Id,Amount,Paid,PurchaseDate");

            // Loop through the list of records and write each record to the CSV file
            foreach (Record record in Records)
            {
                writer.WriteLine("{0},{1},{2}", record.Amount, record.Paid, record.PurchaseDate);
            }
        }

        conn.Close();
    }

Anyone know how to do that?


EDIT:

The solutions provided in the comments below seem to be Windows and MacOS based. I am looking for an Android based solution.

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • Does this answer your question? [Folder Picker .NET MAUI](https://stackoverflow.com/questions/70999773/folder-picker-net-maui) – Jason Dec 16 '22 at 16:13
  • https://stackoverflow.com/questions/72336035/is-there-a-dialog-for-saving-files-in-net-maui – Hans Passant Dec 16 '22 at 16:14
  • @Jason, that solution seems to be Windows MacOS based. – oshirowanen Dec 16 '22 at 16:25
  • @HansPassant, that solution seems to be Windows MacOS based. – oshirowanen Dec 16 '22 at 16:25
  • 2
    Then build a picker (or similar UI) with a list of folder options. iOS/Android don't typically give the use broad access to the file system so allowing them to choose a save location isn't a common task – Jason Dec 16 '22 at 16:26
  • `Android 12` requires use of `Storage Access Framework`, for files that might be visible to other apps. [Access documents and other files from shared storage](https://developer.android.com/training/data-storage/shared/documents-files). Also see https://stackoverflow.com/a/74830261/199364. Xamarin and Maui should be identical (except for `Maui` namespaces instead of `Xamarin` ones). – ToolmakerSteve Dec 17 '22 at 01:29

0 Answers0