大家帮忙看看这个错误 期待ing...
网页上文件上传功能发生的错误。如:我们用file field html 控件
设置它的enctype为multipart
再放置一个listbox用于显示上传的文件列表
放置按钮,在它的click事件中:
private void butUpLoad_Click(object sender, System.EventArgs e)
{
string strFileName=filUpLoad.PostedFile.FileName;//运行是显示这里错误
strFileName=System.IO.Path.GetFileName(strFileName);
try
{
if(filUpLoad.PostedFile.ContentLength==0)
throw new
System.IO.FileNotFoundException();
filUpLoad.PostedFile.SaveAs(Request.MapPath(Request.ApplicationPath)+ "\\ "+strFileName);
lstServerFiles.Items.Add(strFileName);
lstServerFiles.SelectedIndex=0;
}
catch(System.NullReferenceException ex)
{
Response.Write( "未将对象引用到实例 ");
}
catch(System.IO.FileNotFoundException ex)
{
Response.Write( " <p> no thi file </p> "+ex.Message+ " <br> ");
}
catch(System.IO.IOException ex)
{
Response.Write( " <p> thi file can not be saved "+ "to the server. </p> ");
}
catch(System.Net.WebException ex)
{
Response.Write( " <p> an internet error occurred while "+ "uploading the file. </p> ");
}
catch(Exception ex)
{
Response.Write( " <p> the following error occured : "+ex.Message+ " <br> ");
}
finally
{
//Response.Write( "error occurred ");
filUpLoad.Value= " ";
}
}
下面是相关错误信息:
“/UpLoadTest”应用程序中的服务器错误。
--------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 50: private void butUpLoad_Click(object sender, System.EventArgs e)
行 51: {
行 52: string strFileName=filUpLoad.PostedFile.FileName;
行 53: strFileName=System.IO.Path.GetFileName(strFileName);
行 54: try
源文件: c:\inetpub\wwwroot\uploadtest\webform1.aspx.cs 行: 52
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
UpLoadTest.WebForm1.butUpLoad_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\uploadtest\webform1.aspx.cs:52
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessReque