private WebClient MyWebClient = new WebClient();
void MyWebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if ((e.Cancelled == true))
{
MessageBox.Show("上传文件操作被取消!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("上传文件操作完成!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void Form1_Load(object sender, EventArgs e)
{
MyWebClient.UploadProgressChanged += new UploadProgressChangedEventHandler(MyWebClient_UploadProgressChanged);
MyWebClient.UploadFileCompleted += new UploadFileCompletedEventHandler(MyWebClient_UploadFileCompleted);
}
void MyWebClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
this.progressBar1.Value = e.ProgressPercentage;
this.label3.Text = "已经上传" + e.BytesSent.ToString() + "字节,全部共有" + e.TotalBytesToSend.ToString() + "字节";
//throw new Exception("The method or operation is not implemented.");
}
//开始上传
private void button1_Click(object sender, EventArgs e)
{
try
{
this.progressBar1.Value = 0;
this.MyWebClient.UploadFileAsync(new Uri(this.textBox1.Text), this.textBox2.Text);
}
catch (Exception MyEx)
{
MessageBox.Show(MyEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//取消上传
private void button2_Click(object sender, EventArgs e)
{
MyWebClient.CancelAsync();
}
void MyWebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if ((e.Cancelled == true))
{
MessageBox.Show("上传文件操作被取消!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("上传文件操作完成!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void Form1_Load(object sender, EventArgs e)
{
MyWebClient.UploadProgressChanged += new UploadProgressChangedEventHandler(MyWebClient_UploadProgressChanged);
MyWebClient.UploadFileCompleted += new UploadFileCompletedEventHandler(MyWebClient_UploadFileCompleted);
}
void MyWebClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
this.progressBar1.Value = e.ProgressPercentage;
this.label3.Text = "已经上传" + e.BytesSent.ToString() + "字节,全部共有" + e.TotalBytesToSend.ToString() + "字节";
//throw new Exception("The method or operation is not implemented.");
}
//开始上传
private void button1_Click(object sender, EventArgs e)
{
try
{
this.progressBar1.Value = 0;
this.MyWebClient.UploadFileAsync(new Uri(this.textBox1.Text), this.textBox2.Text);
}
catch (Exception MyEx)
{
MessageBox.Show(MyEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//取消上传
private void button2_Click(object sender, EventArgs e)
{
MyWebClient.CancelAsync();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货