就是用程序简单的把文件下载到本地
解决方案 »
- SendMessage 模拟鼠标点击指定坐标
- sqlconnection open方法卡主了
- 怎样在C#程序中使用esc键退出全屏模式??
- 怎么 删除数组中指定的数据呢
- VS2010 MFC 里如何使用 CFolderPickerDialog
- SqlParameter 对象的name属性值为什么要用@?
- 应用程序中的服务器错误
- 神啊,给我一个能用的telnet并捕获执行命令的代码吧
- 难题,高手请进.有谁做过或知道像vss中的那样当添加文件的时候弹出一个对话框(小弟分不够,把所有的用尽都只有30分,不好意思,有谁解决以后
- 请教一下谁写过客户端与服务端通信
- 用户控件的引用问题
- 索引化属性是怎么回事啊?
C#
public void DownloadFile (
string address,
string fileName
)
参数
address
从中下载数据的 URI。 fileName
要接收数据的本地文件的名称。
WebClient.DownloadFile (String, String)
将具有指定 URI 的资源下载到本地文件。
先添加引用COM->Microsoft Xml, v3.0
下面的StringFilePath参数是指存放目录,fn是指含文件后缀的完整文件名
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if( _xmlhttp.readyState == 4 )
{
if(System.IO.File.Exists(HttpContext.Current.Server.MapPath(StringFilePath +"/"+ fn)))
System.IO.File.Delete(HttpContext.Current.Server.MapPath(StringFilePath +"/"+ fn));
System.IO.FileStream fs = new System.IO.FileStream(HttpContext.Current.Server.MapPath(StringFilePath +"/"+ fn), System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
try
{
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
catch()