首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

大家帮忙看看这个异常 期待ing.

2011-12-27 
大家帮忙看看这个错误 期待ing...网页上文件上传功能发生的错误。如:我们用filefieldhtml控件设置它的encty

大家帮忙看看这个错误 期待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.ProcessRequestMain()

 

大家看看什么问题

[解决办法]
上传到Web服务器,用户必须要有相应的权限

如果是Win2000,请添加ASPNET用户的写权限

如果是Winxp or win2003 请添加NetWork Service用户的写权限



具体操作

鼠标右键你要上传得文件夹 -- 属性 -- 安全 -- 添加 输入相应的用户名 确定 -- 给与相应的权限 -- 确定
[解决办法]
先看看你用来保存上传文件的目录是否用足够的权限
需要添加 Internet来宾用户 并赋予其 修改权限

热点排行