Search code examples
c#filepdffilecontentresult

C# FileContentResult File Download In Custom Folder


I'm using FileContentResult method to download a generated PDF file. After running this code

public FileContentResult genPDF(PDFFileData m)
{
    try
    {
        var FL = generatePDF(m);
        var FLBytes = System.IO.File.ReadAllBytes(FL.FullName);
        return File(FLBytes, "application/pdf", "PDF_FILE.pdf");
    }
    finally
    {
        sendEmail();
    }
}

file is saved in my downloads folder by default. How can I change that? I want to save this file in a custom folder.


Solution

  • As you are returning a file from a web server you are unable to change the default file location as that setting is decided by the web browser rather than the server.

    if you are using Chrome, for example you are able to alter the settings to ask where to save a file on download rather than automatically saving the file to the downloads folder.

    A example of where you can set the prompt to ask you where to save the file in chrome