如何下载WinForm应用程序内从网络上的文件 [英] How to download a file from the web within a WinForm application

查看:133
本文介绍了如何下载WinForm应用程序内从网络上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我书面方式,我需要下载和保存从URL文件的能力一个C#应用程序。

I'm writting a C# utility program that I need the ability to download and save a file from a URL.

我的代码工作取得网址从Web服务调用,但是我无法找到如何开始下载和数据保存到磁盘文件中一个简单的例子。

I have the code working to obtain the URL from a web service call, however I'm having trouble finding a simple example of how to begin the download and save the data to a disk file.

有没有人有一个这很好的例子,也可以为我提供一个例子吗?

Does anyone have a good example of this, or can provide me with an example?

感谢

编辑 - !我应该指出,这些文件将在3到4 GB的大小。所以,如果有这种规模我将不胜感激任何意见文件的特殊注意事项

EDIT - I should mention that these files will be 3 to 4 GB in size. So if there are special considerations for files of this size I would appreciate any advice.

推荐答案

WebClient.DownloadData ,该规范包含一个小样本。这可以说是更有效地使用 WebRequest.GetResponseStream 并节省块中的数据块,但你必须要好好准备的WebRequest 自己。

更新

如果您要下载的文件3-4GB,那么你必须做很多比.net框架更提供。 Web客户端是immedeatly外的非问题,因为它返回的内容作为一个整体的byte []。即使假设您VAS(虚拟地址空间)的的的contigous 4GB刻录这些下载,净不能alocate的任何的大于2Gb(x64上为好)。所以,你的必须的使用的流,如GetResponseStream()。

If you have to download 3-4GB files then you must do much much more than what the .Net framework offers. WebClient is immedeatly out-of-the-question since it returns the content as one monolithic byte[]. Even presuming that your VAS (virtual address space) has the contigous 4GB to burn on these downloads, .Net cannot alocate anything larger than 2Gb (on x64 as well). So you must use streams, as in GetResponseStream().

其次,你必须实现HTTP范围单位您的要求,按照的 HTTP / 1.1 3.12节。您的请求必须包含内容范围头才能够恢复intrerupted下载。当然,你的目标服务器将不得不接受并承认这些标题,也许有prpoer 接受-范围,这几台服务器做回应。

Second you must implement HTTP range units in your request, as per HTTP/1.1 section 3.12. Your request must contain Content-Range headers to be able to resume intrerupted downloads. And of course, your target server will have to accept and recognize these headers, and perhaps respond with a prpoer accept-ranges, which few servers do.

你有你的盘子已经满了,下载4Gb的是什么,但微不足道。

You have your plate full, downloading 4Gb is anything but trivial.

这篇关于如何下载WinForm应用程序内从网络上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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