社区
C#
帖子详情
WinForm会的进来看看
namcer8816
2012-07-24 09:01:15
我想实现 winfrom窗体中 button事件 实现,当点击时候下载制定文件路径的zip 文件。 帮帮忙 新手啊
!!
...全文
135
7
打赏
收藏
WinForm会的进来看看
我想实现 winfrom窗体中 button事件 实现,当点击时候下载制定文件路径的zip 文件。 帮帮忙 新手啊 !!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
hlqnlbsn627
2012-07-24
打赏
举报
回复
楼猪加油,我也在想这个问题
lenovore
2012-07-24
打赏
举报
回复
using System.Net;
using System.IO;
/// <summary>
/// 下载服务器至客户端
/// </summary>
/// <param name="URL">被下载的地址, 绝对路径</param>
/// <param name="Dir">另存放的目录</param>
public static void Download(string URL, string Dir)
{
WebClient client = new WebClient();
string fileName = URL.Substring(URL.LastIndexOf("/") + 1); //被下载的名
string Path = Dir + fileName; //另存为的绝对路径+名
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
//request.Timeout = 300000;
request.KeepAlive = true;
request.AllowAutoRedirect = true;
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 2.0.50727; CIBA)";
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse webresponse = null;
try
{
webresponse = request.GetResponse() as HttpWebResponse;
if (webresponse != null)
{
Stream st = webresponse.GetResponseStream();
Stream so = new FileStream(Path, FileMode.Create);
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
so.Write(by, 0, osize);
osize = st.Read(by, 0, (int)by.Length);
}
so.Close();
st.Close();
}
}
catch (System.Exception e)
{
}
finally
{
if (webresponse != null)
{
webresponse.Close();
webresponse = null;
}
if (request != null)
{
request.Abort();
request = null;
}
}
}
sjms_xf1
2012-07-24
打赏
举报
回复
这个问题不难,对不起是在没时间写这个,友情帮顶了,免得你沉贴
shizhusz110
2012-07-24
打赏
举报
回复
一楼正确+
SocketUpEx
2012-07-24
打赏
举报
回复
不行就不行了
[Quote=引用 2 楼 的回复:]
引用 1 楼 的回复:
using System;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebClient webClient = new WebClient();
webClient.DownloadFil……
[/Quote]
namcer8816
2012-07-24
打赏
举报
回复
[Quote=引用 1 楼 的回复:]
using System;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebClient webClient = new WebClient();
webClient.DownloadFile(u……
[/Quote]
不行啊!
SocketUpEx
2012-07-24
打赏
举报
回复
using System;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
WebClient webClient = new WebClient();
webClient.DownloadFile(url, path);
Console.ReadKey();
}
}
}
C# for CSDN 乱七八糟的看不懂
后,只要 L2 生命期没有终结,它的以后的变化就可能
会
影响到 L1 的数值。因 此在赋值后应该及时销毁或者初始化 L2,以免发生不可预见的错误。 比较 使用 Contains 方法。 ArrayList Array1=new ArrayList(); Array1...
PerCM个人代码管理软件
随着编写几个类似程序并且不断总结反思,的确在
winform
程序编写的能力上有了一定的提高,对于解决问题,开始有了独立的思考。但是必须认识到自己所处于的不利状态,所以集聚所有的资源,去开发一个有用好用的程序...
asp.net知识库
.Net 中IE使用
WinForm
控件的使用心得。 动态加载用户控件的组件!(终结MasterPages技术) 在ASP.NET 1.1下实现模板化站点的新思路 在ASP.Net中两种利用CSS实现多界面的方法 用于弹出ModalDialog进行数据选择的控件 ...
winform
html5桌面,开启新模式
WinForm
- Jokerpapapa
从今天开始咱们正式进入
WinForm
开发模式首先很官方的介绍下什么是
winform
:客户端应用程序:C/S这就是
winform
有什么特别特别重要的特点呢:可以操作用户电脑上的文件举个简单的例子:很多人都玩过LOL/CF/DOTA/CS/DNF...
winform
中导入excel表格
winform
中导入表格的方法有很多种,这里是用Gridview来存放从表格中导入的数据的,当然在此之前你要先从工具栏中拖一个openFileDialog
进来
才能用 //导入按钮点击事件 private void btnImport_Click(object sender, ...
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章