dim file as HttpPostedfile = Fileup.Postedfile
dim dfile as file
 If file.contentlength<>0 then  变量最好不要用file,改一个变量名吧。用myFiledim myFileas HttpPostedfile = Fileup.Postedfile
dim dfile as file
'测试的时候,可先判断是否为空,语法不知道对不对:
if myFile <> nothing  then
 If myFile.contentlength<>0 then  

解决方案 »

  1.   

    同意 qwbyxw(随缘) 的说法,用的时候一定判断空,我遇到过这种情况,可先判断 Fileup.Postedfile 是否为空,还有 Fileup.Postedfile.FileName 是否为空
      

  2.   

    if((Fileup.PostedFile!=null)&&(Fileup.PostedFile.FileName!="")) [C#语法]
      

  3.   

    <input type="file" runat="server">
      

  4.   

    可以先用try和catch来检测一下是哪个引用出错了!然后做出修改就好了 ,这个错误是因为你在某个地方引用了 一个null对象,所以你要看看你的代码中有没有出现这种情况的地方!
      

  5.   

    不要定义dim file as HttpPostedfile = Fileup.Postedfile了,直接用Fileup.Postedfile操作,记得用上面的判断方法,先行判断,如果还不成请回复
      

  6.   

    我也遇到过这种情况,代码在本地用没有问题,一传到服务器就出错,要说没有将变量初始化,那为什么在本地时不出错呢?
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       xingzhengcf.gongcheng_xuanzhe.datarefresh() in c:\inetpub\wwwroot\xzcfys\gongcheng_xuanzhe.aspx.vb:48
       xingzhengcf.gongcheng_xuanzhe.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\xzcfys\gongcheng_xuanzhe.aspx.vb:31
       System.Web.UI.Control.OnLoad(EventArgs e) +67
       System.Web.UI.Control.LoadRecursive() +29
       System.Web.UI.Page.ProcessRequestMain() +724
      

  7.   

    上传控件事客户端的控件,你点提交后file.value为空,所以出错
      

  8.   

    killprograme(浪漫之恋) 
    上传控件事客户端的控件,你点提交后file.value为空,所以出错有什么解决办法代码在本地怎么不出错?
      

  9.   

    <%@ Import Namespace="System.IO" %>
    <%@ page Language="C#" debug="true" %>
    <html>
    <head>
    <title>上传文件 , http://www.chinabs.net </title>
    <script language="C#" runat="server">
     //This method is called when the "upload" button id pressed
     public void UploadFile(object sender , EventArgs E)
     {
       //检查上传文件不为空
       if(myFile.PostedFile!=null)
       {     
      string nam = myFile.PostedFile.FileName ;
      //取得文件名(抱括路径)里最后一个"."的索引
      int i= nam.LastIndexOf(".");
      //取得文件扩展名
      string newext =nam.Substring(i);
      //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
      DateTime now = DateTime.Now; 
      string newname=now.DayOfYear.ToString()+myFile.PostedFile.ContentLength.ToString(); 
      //保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
      //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
      myFile.PostedFile.SaveAs(Server.MapPath("\\upload\\"+newname+newext)); 
      //得到这个文件的相关属性:文件名,文件类型,文件大小
      fname.Text=myFile.PostedFile.FileName;
      fenc.Text=myFile.PostedFile.ContentType ;
      fsize.Text=myFile.PostedFile.ContentLength.ToString();
       }
     }</script>
      

  10.   

    上传文件你的form应该这样定义<form id="formName" method="post" encType="multipart/form-data" runat="server">不过你既然本地能通过,应该也是按照这样添加了 encType属性说明了吧?
      

  11.   

    刚刚解决了  是忘记改FORM的属性了  呵呵 谢谢大家
    但是觉得奇怪的是没有加encType属性说明本地也能通过的