2

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.

Brandon Minnick
  • 11,396
  • 12
  • 55
  • 108

1 Answers1

4

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

Darren
  • 318
  • 1
  • 14
  • That is correct. Suppose that any web server would have access to the complete directory structure of your local machine. That would be a serious security hazard. Yet that "feature" is the implied wish of the OP. – Bruno Lowagie Aug 04 '17 at 08:31
  • I can use downloads folder but if client has configured a different default location that will cause an error. –  Aug 04 '17 at 08:34
  • Could you include of the error the client is experiencing in either a new question or amend your question? As that shouldn't be causing an issue. – Darren Aug 04 '17 at 08:37
  • There are no errors yet, I just wanted to save the PDF file in a particular directory and then send it using SMTP Client. Is there any chance to convert byte array into the email attachment? That would be perfect because I wouldn't have to download the file at all. –  Aug 04 '17 at 08:55
  • @theCodeFighter You can create a PDF in memory *on the server side*, attach the bytes of that PDF to a mail *on the server side*, and send that mail to an end user. You don't have access to all of this on the client side for obvious reasons; imagine you could send mails from the computer of every visitor of your web site. That would be crazy! – Bruno Lowagie Aug 04 '17 at 12:22