locked
Path.GetTempFIleName() wont save as pdf in temp folder RRS feed

  • Question

  • User2037455357 posted

    Hello there.

    I have an ASP.Net application, and one part that saves a pdf works when debugging, but not when deployed over the web.

    this is the snippet im having an issue with

    string pdfFileName = Path.ChangeExtension(Path.GetTempFileName(), ".pdf");

    pdf.save(pdfFileName)

    The pdf.save is from a framework called pdfsharp.

    This should save within the temp folder, but does not.  Is there something else i need to do for this to work over the web?

    Could i save this to the browsing PC download folder instead???

    Monday, November 30, 2020 8:48 PM

All replies

  • User475983607 posted

    This should save within the temp folder, but does not.  Is there something else i need to do for this to work over the web?

    Could i save this to the browsing PC download folder instead???

    The file is saved on the server not the client machine.  It is not possible for a web application to save a file on a use's machine.  The design seems to work during development because the development machine is both the server and the client.  Once deployed the design no longer works. 

    Monday, November 30, 2020 9:19 PM
  • User753101303 posted

    Hi,

    You mean you expect this file to be saved on the browser machine? A common catch for beginners (though you have 370 posts ?) is that you often develop on your own machine with the very special situation where it is both the web server and the browser side machine.

    But keep in mind that once deployed on a real server, this code runs on the web server and will write at best to server side disks. A web server doesn't have direct to browser side disks.

    Monday, November 30, 2020 9:19 PM
  • User2037455357 posted

    what’s 370 posts got to do with it????

    Monday, November 30, 2020 9:52 PM
  • User2037455357 posted

    Hi mgebhard. 

    thank you. i’m always learning. The application is currently deployed on an ftp so i think i will look at saving the pdf to the ftp, then viewing it from there. 

    Monday, November 30, 2020 9:56 PM
  • User2037455357 posted

    How do i save to client pc download folder instead. i know that is possible. 

    Monday, November 30, 2020 10:15 PM
  • User475983607 posted

    thank you. i’m always learning. The application is currently deployed on an ftp so i think i will look at saving the pdf to the ftp, then viewing it from there.

    I'm not sure what you are stating.  FTP is a protocol for moving files.  If you have a PDF file that you wish to share then FTP is a good way to get the file to the host.

    How do i save to client pc download folder instead. i know that is possible. 

    It is NOT possible for a website to save a file on the client PC.  

    Either create a link the user clicks to download the file or return a File from an Action method.  The browser will save the file in the downloads folder.  The user can move the file wherever they like.

    Monday, November 30, 2020 10:34 PM
  • User753101303 posted

    Don't know about your experience but it seemed you should have been exposed to that difference already or you worked for quite some time on this app and this is your first deployment attempt?

    A web server doesn't have any direct access to client side disks. Instead it can send an httpresponse that will trigger a download dialog in the browser: https://weblog.west-wind.com/posts/2007/may/21/downloading-a-file-with-a-save-as-dialog-in-aspnet

    Monday, November 30, 2020 11:23 PM