注册 登录
编程论坛 ASP.NET技术论坛

为什么老是出现“未将对象引用设置到对象的实例”

发布于 2008-07-24 15:35, 1639 次点击
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 132:                        
行 133:                        HttpPostedFile hpf=F.PostedFile;
行 134:                        int cl=hpf.FileName.Length;
行 135:                        
行 136:                        if(cl>0)
5 回复
#2
hebingbing2008-07-24 16:32
对象没有new
#3
2008-07-24 17:34
能说清楚点吗 哪个地方要加new啊 单独的上传程序 我以前都没加过new啊
#4
xyq7018302008-07-24 19:45
你是用什么写的......
#5
2008-07-25 00:17
我的上传控件是html组件中的file filed 将他转化为服务器控件运行 代码如下:

    HttpPostedFile hpf=F.PostedFile;
                        int cl=hpf.FileName.Length;
                        
                        if(cl>0)
                        {
                            if(hpf.FileName=="")
                            {
            
                                RegisterStartupScript("","<script>alert('你上传的文件不能为空!')</script>");

                            }
                            else
                            {
                                string kuo=Path.GetExtension(hpf.FileName).ToLower();
                                if(kuo==".jpg" || kuo==".gif" || kuo==".bmp" )
                                {
                
                                    if(hpf.ContentLength<660000)
                                    {
                                        filename=DateTime.Now.ToString("yyyMMdd")+Path.GetFileName(hpf.FileName);
                                        string filepath=Server.MapPath("loadfile/");
                                        hpf.SaveAs(filepath+filename);

                                    }
                                    else
                                    {
                                        RegisterStartupScript("","<script>alert('请将你所上传的文件控制在600kb内!')</script>");
                                    }
                                }
                                else
                                {
                                    RegisterStartupScript("","<script>alert('上传图片的格式要为jpg,gif,bmp!')</script>");
                                }
                            }
                        }
                        else
                        {
                            filename=face;
                        }


                        conndb cdb=new conndb();
                        int i=cdb.reg(xm,mm,filename,xb,qm,yx,wt,da,lz);
                        FormsAuthentication.SetAuthCookie(i.ToString(),false);
#6
2008-07-25 00:46
看了看加了一个try catch就好了  估计是if(cl>0)跟本获取到值
估计和隐藏有关  因为默认的上传所在的表格是隐藏的 当把他点开了 就没有出现这样的问题了
1