我编写了一段用于上传文件的代码但是出错了请高手指正下,怎么做
private void button1_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.textBox1.Text=this.openFileDialog1.FileName;
}
} private void button2_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text=="" || this.textBox2.Text=="")
return;
WebClient MyClient=new WebClient();
string URL=this.textBox1.Text;
string FileName=this.textBox2.Text;
byte[] MyResponseArray=null;
try
{
MyResponseArray=MyClient.UploadFile(URL,FileName);
MessageBox.Show("文件上传成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("文件上传失败!错误是:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
finally
{
MessageBox.Show("\n 服务器的回复为: \n"+System.Text.Encoding.ASCII.GetString(MyResponseArray) );
}
}给出来的错误信息是:未处理的“System.ArgumentNullException”类型的异常出现在 mscorlib.dll 中。其他信息: 数组不能为空。
private void button1_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.textBox1.Text=this.openFileDialog1.FileName;
}
} private void button2_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text=="" || this.textBox2.Text=="")
return;
WebClient MyClient=new WebClient();
string URL=this.textBox1.Text;
string FileName=this.textBox2.Text;
byte[] MyResponseArray=null;
try
{
MyResponseArray=MyClient.UploadFile(URL,FileName);
MessageBox.Show("文件上传成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("文件上传失败!错误是:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
finally
{
MessageBox.Show("\n 服务器的回复为: \n"+System.Text.Encoding.ASCII.GetString(MyResponseArray) );
}
}给出来的错误信息是:未处理的“System.ArgumentNullException”类型的异常出现在 mscorlib.dll 中。其他信息: 数组不能为空。
解决方案 »
- c#调用CAD画图,并获取图片保存路径
- 我要获取电脑的域名,工作组名,要用什么呀?
- [重奖100分]帮我看一下,读Excel问题
- 把TabControl中某TabPage移除,然后调用TabPage的Dispose,结果为什么一次移除了两个? 迷惑不解
- 请问各位C#大虾,哪里能下载到一些C#写的程序
- 初学ado.net,请教一个问题
- 关于经纬度计算问题,急!高手进
- 如何写正则表达式可以匹配这样的字符串:"一个中文字"加"一个英语字母"加一个"全角或半角符号之一" ?
- winform中Application.Run(new Main());这个语句报错怎么回事?
- 求一个生成guid 方法以及验证方法,不能用mac,不能用ip,不能用cpuid
- C#如何缩放图片不失真?
- 那位可以举个简单的例子说明,基于事件的异步模式..
MessageBox.Show("\n 服务器的回复为: \n"+System.Text.Encoding.ASCII.GetString(MyResponseArray) );withif( MyResponseArray != null && MyResponseArray.Length > 0 )
MessageBox.Show("\n 服务器的回复为: \n"+System.Text.Encoding.ASCII.GetString(MyResponseArray) );
在WebClient请求期间发生异常 ,这是为什么?