如何从mvc中的webgrid下载一个从数据库中获取的文件? [英] How to download a file from a webgrid in mvc which are fetching from database?

查看:60
本文介绍了如何从mvc中的webgrid下载一个从数据库中获取的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从mvc中的webgrid下载一个从数据库中提取的文件?

How to download a file from a webgrid in mvc which are fetching from database??

推荐答案

如果你是通过HTTP下载文件,那没关系什么是服务器端,MVC与否。您只需要使用类 System.Net.HttpWebRequest ,或者有时,简化类 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 [ ^ ]。



顺便提一下,作为参考,你可以使用我在这里提供的HTTPDownloader的源代码:如何从互联网上下载文件 [ ^ ]。



它涵盖了大多数常见案例,但并不适用于所有情况,因为它不处理身份验证和HTTP请求的其他细节。原则上,除了同一站点上的某个特定页面之外,站点可以应用许多预防措施来拒绝来自任何地方的HTTP请求。有时,您可以使用一些HTTP间谍工具了解请求的所有细节,并将其复制到您的下载代码中。我在下面提到的一个过去的答案中提到过它。



另见我过去的答案:

如何从Asp.net 2.0中的服务器下载文件 [ ^ ],

FTP:下载文件 [ ^ ],

如何从其他网站获取数据 [ ^ ],

从网页中获取特定数据 [ ^ ],

执行某种Web请求并获得结果 [< a href =http://www.codeproject.com/Answers/820024/Performing-a-some-kind-of-Web-Request-and-getting#answer1target =_ blanktitle =New Window> ^ ]。



另请参阅: http:// en.wikipedia.org/wiki/Web_scraping [ ^ ]。



-SA
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


这篇关于如何从mvc中的webgrid下载一个从数据库中获取的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆