-1

I'm exporting a file directly into the Downloads folder, like so:

private async Task ExportDB()
    {
        string downloadsPath = SHGetKnownFolderPath(Guid.Parse("374DE290-123F-4565-9164-39C4925E467B"), 0);
        exportJson = await Database.ExportDB();
        string formattedJson = JValue.Parse(exportJson).ToString(Formatting.Indented);
        string fullPath = downloadsPath + "\\exported_db.json";
        File.WriteAllText(fullPath, formattedJson);
    }

However, I want to trigger the download event on my browser to show the downloads window (like it usually does when we download something from the browser). How can I trigger that event?

RicardoP
  • 187
  • 8
  • Does this answer your question? [How can one generate and save a file client side using Blazor?](https://stackoverflow.com/questions/52683706/how-can-one-generate-and-save-a-file-client-side-using-blazor) – NineBerry Mar 20 '23 at 13:04
  • Does this answer your question? [How to produce a file to download containing a JSON structure?](https://stackoverflow.com/questions/54543808/how-to-produce-a-file-to-download-containing-a-json-structure) – Leandro Bardelli Mar 20 '23 at 17:02

1 Answers1

0

YOU NEED USE A FUNCTION JS

function saveAsFile(filename, bytesBase64) {
    var link = document.createElement('a');
    link.download = filename;
    link.href = "data:application/octet-stream;base64," + bytesBase64;
    document.body.appendChild(link); // Needed for Firefox
    link.click();
    document.body.removeChild(link);
}