首页 > Windows开发 > 详细

C#实现在winfrom程序中下载文件

时间:2016-01-07 18:09:10      阅读:388      评论:0      收藏:0      [点我收藏+]
//下载文件
public static void downfile(string downloadUrl,string filename,string filepath) { HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downloadUrl); hwr.Timeout = 15000; HttpWebResponse hwp = (HttpWebResponse)hwr.GetResponse(); Stream ss = hwp.GetResponseStream(); byte[] buffer = new byte[10240]; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } FileStream fs = new FileStream( string.Format(filepath + @"\" + filename), FileMode.Create); try { int i; while ((i = ss.Read(buffer, 0, buffer.Length)) >0) { fs.Write(buffer, 0, i); } fs.Close(); ss.Close(); } catch (Exception) { throw; } }

 

C#实现在winfrom程序中下载文件

原文:http://www.cnblogs.com/youmingkuang/p/5110674.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!