private void StartDownload()
{
Start.Enabled = false;
string URL = srcAddress.Text;
int n = URL.LastIndexOf("/");
string URLAddress = URL.Substring(0,n);
string fileName = URL.Substring(n+1,URL.Length-n-1);
string Dir = tarAddress.Text;
string Path = Dir+"\\"+fileName;
try
{
WebRequest myre=WebRequest.Create(URLAddress);
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"Error");
}
try
{
statusBar.Text = "开始下载文件...";
client.DownloadFile(URLAddress,fileName);
Stream str = client.OpenRead(URLAddress);
StreamReader reader = new StreamReader(str);
byte[] mbyte = new byte[100000];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
statusBar.Text = "正在接收数据...";
while(allmybyte>0)
{
int m = str.Read(mbyte,startmbyte,allmybyte);
if(m==0)
break;
startmbyte+=m;
allmybyte-=m;
}
FileStream fstr = new FileStream(Path,FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);
str.Close();
fstr.Close();
statusBar.Text = "下载完毕!";
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"Error");
statusBar.Text = "";
}
Start.Enabled = true;
} 用C#写的一个文件下载器 在WebException exp 弹出异常错误
断点Stream str = client.OpenRead(URLAddress); 监视提示内容为: OpenRead 错误: 标识符“OpenRead”超出范围
我给的URL没有问题阿!
这是怎么回事啊,高手帮忙看看,谢谢了 阿门~
{
Start.Enabled = false;
string URL = srcAddress.Text;
int n = URL.LastIndexOf("/");
string URLAddress = URL.Substring(0,n);
string fileName = URL.Substring(n+1,URL.Length-n-1);
string Dir = tarAddress.Text;
string Path = Dir+"\\"+fileName;
try
{
WebRequest myre=WebRequest.Create(URLAddress);
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"Error");
}
try
{
statusBar.Text = "开始下载文件...";
client.DownloadFile(URLAddress,fileName);
Stream str = client.OpenRead(URLAddress);
StreamReader reader = new StreamReader(str);
byte[] mbyte = new byte[100000];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
statusBar.Text = "正在接收数据...";
while(allmybyte>0)
{
int m = str.Read(mbyte,startmbyte,allmybyte);
if(m==0)
break;
startmbyte+=m;
allmybyte-=m;
}
FileStream fstr = new FileStream(Path,FileMode.OpenOrCreate,FileAccess.Write);
fstr.Write(mbyte,0,startmbyte);
str.Close();
fstr.Close();
statusBar.Text = "下载完毕!";
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"Error");
statusBar.Text = "";
}
Start.Enabled = true;
} 用C#写的一个文件下载器 在WebException exp 弹出异常错误
断点Stream str = client.OpenRead(URLAddress); 监视提示内容为: OpenRead 错误: 标识符“OpenRead”超出范围
我给的URL没有问题阿!
这是怎么回事啊,高手帮忙看看,谢谢了 阿门~
statusBar.Text = "开始下载文件...";
client.DownloadFile(URLAddress,fileName);
Stream str = client.OpenRead(URLAddress);
谢谢哦