i have created method creates , saves pdf directory in project. unable file download after created however. have tried several options have seen on stack overflow, , numerous other sites. can see pdf content in response in firebug, , can open file manually, no file download. please help.
controller
public class signaturecontroller : controller { // get: signature public filecontentresult index(string ordernumber) { var pdffile = documentgenerator.generatesigneddocument(ordernumber); byte[] filedata = system.io.file.readallbytes(pdffile); string contenttype = mimemapping.getmimemapping(pdffile); system.net.mime.contentdisposition cd = new system.net.mime.contentdisposition { filename = pdffile, inline = true, }; response.appendheader("content-disposition", cd.tostring()); return file(filedata, contenttype); } } pdf generator
public static string generatesigneddocument(string ordernumber) { ............... string currentdate = datetime.now.tostring("mmddyyyy"); string filename = hostingenvironment.mappath(pdftemppath) + ordernumber + currentdate + ".pdf"; pdfdocument.save(filename); return filename; } header returning
cache-control
private content-disposition attachment; filename="signed document.pdf" content-encoding
gzip content-type
application/pdf date
thu, 16 jul 2015 16:58:29 gmt server
microsoft-iis/8.0 transfer-encoding
chunked vary
accept-encoding x-aspnet-version
4.0.30319 x-aspnetmvc-version 5.2 x-powered-by
asp.net x-sourcefiles
=?utf-8?b?qzpcvxnlcnnccmphbwvzxfnvdxjjzvxxb3jrc3bhy2vzxen1c3rvbwvyuglja1vwxen1c3rvbwvyuglja1vwlldlylxtawduyxr1cmvcsw5kzxg =?=
set inline false or omit it. way the header attachment (instead of inline).
e.g (this sample downloads file in file system)
public filepathresult downloadpdf() { var cd = new system.net.mime.contentdisposition { filename = "foo.pdf" //inline = false //false or omit }; response.appendheader("content-disposition", cd.tostring()); return file("~/files/somefile.pdf", "application/pdf"); } the header like: content-disposition:attachment; filename=foo.pdf
file name set - sample obtaining pdf file system because don't generate 1 on fly (so code fine byte result). key item return correct header attachment - can set manually
response.appendheader("content-disposition", "attachment; filename=" + pdffile); and not have use system.net.mime.contentdisposition. btw, pdffile variable string (you're using filename property)?
hth...
Comments
Post a Comment