for eg - context.Response.AddHeader("Content-Disposition", "filename=" + "Simple PDF File.pdf");
normally we just specify the name of the file we are uploading..
also, this was just a tip. You should look up details on specifying the header and there are many more properties, like targeting a window, forcing downlod box etc..
lenerd3000
Member
72 Points
151 Posts
pdf download
Jul 21, 2008 01:19 PM|LINK
hi,
i have a problem in my current website project.
I have a link named Download and if i click it, i want a pdf file to be downloaded.
the problem is, every time i click the download my pdf file opens in a browser.
is there any way to make my pdf file downloaded instead of opening in a browser?
One option i got is to zip the pdf but im asking if there is a way to download a pdf file.
please help me.
rollercoaste...
Member
89 Points
34 Posts
Re: pdf download
Jul 21, 2008 01:33 PM|LINK
you need to do this-
context.Response.ClearHeaders();
context.Response.AddHeader("Content-Disposition", "filename=" + PDFFileName);
context.Response.ContentType = "application/pdf";
context.Response.WriteFile(PDFFile);
context.Response.End();
remember to restore ur Respose stream to original values if u want the page to cont with postbacks. This works best from a ashx handler.
lenerd3000
Member
72 Points
151 Posts
Re: pdf download
Jul 21, 2008 02:09 PM|LINK
thank you very much. I really need that code.
can that be use in the hyperlink field control?
rollercoaste...
Member
89 Points
34 Posts
Re: pdf download
Jul 21, 2008 03:27 PM|LINK
you would have to use a linkbutton's click event instead of a hyperlink as this is serverside code..
if you want much clientside you can use javascript to upload the file.
lenerd3000
Member
72 Points
151 Posts
Re: pdf download
Jul 21, 2008 03:43 PM|LINK
ok thank you. but there is a minor issue in the download box. the name specified by the download box is the name of the current page.
how can i change it to the filename of a file that i want to download.
rollercoaste...
Member
89 Points
34 Posts
Re: pdf download
Jul 23, 2008 05:50 AM|LINK
that is what you specify here..
context.Response.AddHeader("Content-Disposition", "filename=" + PDFFileName);
for eg - context.Response.AddHeader("Content-Disposition", "filename=" + "Simple PDF File.pdf");
normally we just specify the name of the file we are uploading..
also, this was just a tip. You should look up details on specifying the header and there are many more properties, like targeting a window, forcing downlod box etc..