Home > Software engineering >  How to download automated word doc to client machine
How to download automated word doc to client machine

Time:07-14

I have created a word document based on an aspx form, the document is created in a different vb.class and I can only save it in a server path in pdf format, I would like this to be downloaded directly to the client machine.

this is the line where I save it to a local path

doc.ExportAsFixedFormat("C:\Users\Franky\Desktop\PAGO Reports" codigoCot ".pdf", Word.WdExportFormat.wdExportFormatPDF)

I have searched the forum for solutions but none has been able to apply to my particular case

CodePudding user response:

Is this a asp.net web site? If yes, then the file system you have for use on the web side of things of course is only folders in the web site. You can certainly save a file into that web site and say one of its folders.

However, when you provide a button for a download link? Well, you can provide a path name to save, but you really have no idea of the existing and valid path names on the client side. In other words, you best in most cases to ONLY provide the file name, and when the user downloads this file from the browser, it will wind up in the downloads folder.

So, from a web site, I don't have the abilty to see, know, or even find out what valid path names exist. But then again, when talking about a web site, it is very much locked down. If this was not the case, then while you come to my web site to look at some cute cat picture? then I would poke around on your computer, and grab your files - things like files called my banking, or pull files called my pass-words.

So, it not 100% clear, if but your talking about a web site, and the user is to download a file that you created on that web site? You have ZERO means to control, determine or even know what is a valid path name on the computer client side. This as noted is done for reasons of security.

your only really practical choice is to allow the user to download the file - and it will wind up and go into the downloads folder.

CodePudding user response:

I am not so farmilia with aspx, but I can try to describe how that will work.

Basically, you make a new file, say pdfdownload.aspx, and in this file, you write some code to:
1.change the content-type header to "application/pdf"
2.output the pdf in raw binary format
(By saying output, I mean sending to the client via http body. Find the methold in aspx with that functionality.)

Avoid outputing anything other than the pdf content.
The browser will handle the rest, previewing or downloading.

  • Related