Download PDF from URL Programatically

Posted by Ganesh961991 under C# on 9/19/2013 | Points: 10 | Views : 1829 | Status : [Member] | Replies : 2
I have link if i open in browser pdf is downloading. Programatically how to save the pdf locally in asp.net c#.





Regards
Ganesh.

Ganesh


Responses

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Here use contentType for PDF files instead of image\jpeg
http://www.west-wind.com/weblog/posts/2007/May/21/Downloading-a-File-with-a-Save-As-Dialog-in-ASPNET


http://stackoverflow.com/questions/5596747/download-stream-file-from-url-asp-net
http://www.csharp-examples.net/download-files/

This link is for download PDF file
http://stackoverflow.com/questions/8590543/force-browser-to-download-pdf-document-instead-of-opening-it

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Ganesh961991, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
http://forums.asp.net/t/1835679.aspx
Instead of using a web service to handle the file download you should look into using an HttpHandler (.ashx file).

Example
public class DownloadFile : IHttpHandler

{
public void ProcessRequest(HttpContext context)
{
string fileName = "HelloWorld.pdf";
string filePath = "C:\\";
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
context.Response.WriteFile(filePath + fileName);
context.Response.End();
}
}

This type of file is basically a lightwieght replacement to the typical aspx page. It has no UI and is ideal for returning simple requests such as a file.


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Ganesh961991, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response