Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to download a file from a webgrid in mvc which are fetching from database??
Posted

1 solution

If you are downloading a file via HTTP, it does not matter what's on the server side, MVC or not. You just need to use the class System.Net.HttpWebRequest or, sometime, simplified class System.Net.WebClient:
https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.110%29.aspx[^].

By the way, for reference, you can use the source code of my HTTPDownloader I provided here: how to download a file from internet[^].

It covers majority of common cases, but does not work in all cases, because it does not deal with authentication and other fine details of HTTP requests. In principle, the site can apply a lot of precautions to deny HTTP requests from anywhere except some certain page on the same site. Sometimes, you can learn all the detail of the request using some HTTP spy tools and replicate it on your downloading code. I mentioned it in one of my past answers referenced below.

See also my past answers:
how to download a file from the server in Asp.net 2.0[^],
FTP: Download Files[^],
How to get the data from another site[^],
get specific data from web page[^],
Performing a some kind of Web Request and getting result[^].

See also: http://en.wikipedia.org/wiki/Web_scraping[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900