下载文件怎么实现 rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要HTTP下载还是FTP下载啊 ? private void DownFile() { if(TempDown!="") { if(Downloading==false) //如果无文件下载 { long fb; this.apc_status_1.Text="正在连接到 " + TempDown; Downloading=true; try { //====尝试URL有效性,以及初始化下载界面 WebRequest myre=WebRequest.Create(TempDown); WebResponse mwrite=myre.GetResponse(); fb=mwrite.ContentLength; this.apc_status_1.Text="连接成功..开始下载.."; pbar.Value=0; pbar.Maximum=(int)fb; pbar.Visible=true; this.ApcList.Height=156; //====开始下载 WebClient wc=new WebClient(); SaveFileDialog sf=new SaveFileDialog(); sf.Title="请选择文件存放的位置"; filename=CurrentFileName; sf.FileName=filename.Substring(filename.LastIndexOf("/")+1,filename.Length-filename.LastIndexOf("/")-1); sf.ShowDialog(this); filename=sf.FileName; if(filename!="") { Stream srm=wc.OpenRead(TempDown); StreamReader srmer=new StreamReader(srm); byte[] mbyte=new byte[fb]; int allbyte=(int)mbyte.Length; int startbyte=0; while(fb>0) //################ 循环读取文件,并显示进度..... { Application.DoEvents(); int m=srm.Read(mbyte,startbyte,allbyte); if(m==0){break;} startbyte+=m; allbyte-=m; pbar.Value+=m; int a1=(int)startbyte/1024; int a2=(int)fb/1024; this.apc_status_1.Text="连接成功..开始下载.." + a1.ToString() + "/" + a2.ToString() + "KB";//startbyte + "/" + fb.ToString(); } FileStream fs = new FileStream(filename,FileMode.OpenOrCreate); fs.Write(mbyte,0,mbyte.Length); fs.Flush(); srm.Close(); srmer.Close(); fs.Close(); this.ApcList.Height=170; pbar.Visible=false; this.apc_status_1.Text="文件下载完毕!"; } } catch(WebException exp) //如地址无效或者找不到文件 { MessageBox.Show(exp.Message,"听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } Downloading=false; } else { MessageBox.Show("对不起,当前正在下载文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } } else { if(WhichDown==1) { MessageBox.Show("当前并无文件播放.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } else { MessageBox.Show("请在列表中选择好想要下载的文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } private void DownFile() { if(TempDown!="") { if(Downloading==false) //如果无文件下载 { long fb; this.apc_status_1.Text="正在连接到 " + TempDown; Downloading=true; try { //====尝试URL有效性,以及初始化下载界面 WebRequest myre=WebRequest.Create(TempDown); WebResponse mwrite=myre.GetResponse(); fb=mwrite.ContentLength; this.apc_status_1.Text="连接成功..开始下载.."; pbar.Value=0; pbar.Maximum=(int)fb; pbar.Visible=true; this.ApcList.Height=156; //====开始下载 WebClient wc=new WebClient(); SaveFileDialog sf=new SaveFileDialog(); sf.Title="请选择文件存放的位置"; filename=CurrentFileName; sf.FileName=filename.Substring(filename.LastIndexOf("/")+1,filename.Length-filename.LastIndexOf("/")-1); sf.ShowDialog(this); filename=sf.FileName; if(filename!="") { Stream srm=wc.OpenRead(TempDown); StreamReader srmer=new StreamReader(srm); byte[] mbyte=new byte[fb]; int allbyte=(int)mbyte.Length; int startbyte=0; while(fb>0) //################ 循环读取文件,并显示进度..... { Application.DoEvents(); int m=srm.Read(mbyte,startbyte,allbyte); if(m==0){break;} startbyte+=m; allbyte-=m; pbar.Value+=m; int a1=(int)startbyte/1024; int a2=(int)fb/1024; this.apc_status_1.Text="连接成功..开始下载.." + a1.ToString() + "/" + a2.ToString() + "KB";//startbyte + "/" + fb.ToString(); } FileStream fs = new FileStream(filename,FileMode.OpenOrCreate); fs.Write(mbyte,0,mbyte.Length); fs.Flush(); srm.Close(); srmer.Close(); fs.Close(); this.ApcList.Height=170; pbar.Visible=false; this.apc_status_1.Text="文件下载完毕!"; } } catch(WebException exp) //如地址无效或者找不到文件 { MessageBox.Show(exp.Message,"听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } Downloading=false; } else { MessageBox.Show("对不起,当前正在下载文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } } else { if(WhichDown==1) { MessageBox.Show("当前并无文件播放.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } else { MessageBox.Show("请在列表中选择好想要下载的文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } } } C#如何读取excel并将数据写入到EXCEL中的? 一个C#有枚举成员的结构体的问题? 17位时间戳如何生成? c#怎样判断不同的数据库 如何向资源文件中添加项,并保存 ???VS2003制作安装文急件的错误!!! TargetInvocationException异常一般都有什么原因额?如何解决呢? 对类的某个方法临时改写的代码排错 datagrid控件中有buttoncolumn这样一个列,点击这一列弹出选择对话框,点确定执行一种操作,点取消执行另外一种操作,如何做呢? C#问题 子窗体间控件访问的问题 control.invoke里面如何调用匿名类
{
if(TempDown!="")
{
if(Downloading==false) //如果无文件下载
{
long fb;
this.apc_status_1.Text="正在连接到 " + TempDown;
Downloading=true;
try
{
//====尝试URL有效性,以及初始化下载界面
WebRequest myre=WebRequest.Create(TempDown);
WebResponse mwrite=myre.GetResponse();
fb=mwrite.ContentLength;
this.apc_status_1.Text="连接成功..开始下载..";
pbar.Value=0;
pbar.Maximum=(int)fb;
pbar.Visible=true;
this.ApcList.Height=156;
//====开始下载
WebClient wc=new WebClient();
SaveFileDialog sf=new SaveFileDialog();
sf.Title="请选择文件存放的位置";
filename=CurrentFileName;
sf.FileName=filename.Substring(filename.LastIndexOf("/")+1,filename.Length-filename.LastIndexOf("/")-1);
sf.ShowDialog(this);
filename=sf.FileName;
if(filename!="")
{
Stream srm=wc.OpenRead(TempDown);
StreamReader srmer=new StreamReader(srm);
byte[] mbyte=new byte[fb];
int allbyte=(int)mbyte.Length;
int startbyte=0;
while(fb>0) //################ 循环读取文件,并显示进度.....
{
Application.DoEvents();
int m=srm.Read(mbyte,startbyte,allbyte);
if(m==0){break;}
startbyte+=m;
allbyte-=m;
pbar.Value+=m;
int a1=(int)startbyte/1024;
int a2=(int)fb/1024;
this.apc_status_1.Text="连接成功..开始下载.." + a1.ToString() + "/" + a2.ToString() + "KB";//startbyte + "/" + fb.ToString();
} FileStream fs = new FileStream(filename,FileMode.OpenOrCreate);
fs.Write(mbyte,0,mbyte.Length);
fs.Flush();
srm.Close();
srmer.Close();
fs.Close(); this.ApcList.Height=170;
pbar.Visible=false;
this.apc_status_1.Text="文件下载完毕!";
}
}
catch(WebException exp) //如地址无效或者找不到文件
{
MessageBox.Show(exp.Message,"听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
Downloading=false;
}
else
{
MessageBox.Show("对不起,当前正在下载文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else
{
if(WhichDown==1)
{
MessageBox.Show("当前并无文件播放.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("请在列表中选择好想要下载的文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
{
if(TempDown!="")
{
if(Downloading==false) //如果无文件下载
{
long fb;
this.apc_status_1.Text="正在连接到 " + TempDown;
Downloading=true;
try
{
//====尝试URL有效性,以及初始化下载界面
WebRequest myre=WebRequest.Create(TempDown);
WebResponse mwrite=myre.GetResponse();
fb=mwrite.ContentLength;
this.apc_status_1.Text="连接成功..开始下载..";
pbar.Value=0;
pbar.Maximum=(int)fb;
pbar.Visible=true;
this.ApcList.Height=156;
//====开始下载
WebClient wc=new WebClient();
SaveFileDialog sf=new SaveFileDialog();
sf.Title="请选择文件存放的位置";
filename=CurrentFileName;
sf.FileName=filename.Substring(filename.LastIndexOf("/")+1,filename.Length-filename.LastIndexOf("/")-1);
sf.ShowDialog(this);
filename=sf.FileName;
if(filename!="")
{
Stream srm=wc.OpenRead(TempDown);
StreamReader srmer=new StreamReader(srm);
byte[] mbyte=new byte[fb];
int allbyte=(int)mbyte.Length;
int startbyte=0;
while(fb>0) //################ 循环读取文件,并显示进度.....
{
Application.DoEvents();
int m=srm.Read(mbyte,startbyte,allbyte);
if(m==0){break;}
startbyte+=m;
allbyte-=m;
pbar.Value+=m;
int a1=(int)startbyte/1024;
int a2=(int)fb/1024;
this.apc_status_1.Text="连接成功..开始下载.." + a1.ToString() + "/" + a2.ToString() + "KB";//startbyte + "/" + fb.ToString();
} FileStream fs = new FileStream(filename,FileMode.OpenOrCreate);
fs.Write(mbyte,0,mbyte.Length);
fs.Flush();
srm.Close();
srmer.Close();
fs.Close(); this.ApcList.Height=170;
pbar.Visible=false;
this.apc_status_1.Text="文件下载完毕!";
}
}
catch(WebException exp) //如地址无效或者找不到文件
{
MessageBox.Show(exp.Message,"听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
Downloading=false;
}
else
{
MessageBox.Show("对不起,当前正在下载文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else
{
if(WhichDown==1)
{
MessageBox.Show("当前并无文件播放.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("请在列表中选择好想要下载的文件.","听啪啪 提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}