if(Session["FileName"].ToString() == "")
{
}
else
{
}
怎么会出错=----未将对象引用设置到对象的实例。
我做的程序是这样的,上传一个文件,记住文件夹名字用Session["FileName"].tostring()
如果没长传点击下一步了就提示操作失败.
但是if(Session["FileName"].ToString() == "")为什么会错啊???

解决方案 »

  1.   

    正确答案if(Session["FileName"].ToString() == null) 
    {
    }
    else
    {

      

  2.   

    如果没上传的时候你有设置Session["FileName"] = string.empty吗?
    如果没有,那当然Session["FileName"]会报错=----未将对象引用设置到对象的实例
    因为它为null,你需要先判断
    if(Session["FileName"]==null)
    {
    //your code
    }
      

  3.   

    Session["FileName"].ToString()      
    session["FileName"]如果是null  你在TOstring() 肯定会出错的.....
      

  4.   

    没有给Session定义的问题啊
    Session["FileName"]=aaa;
    取session才能取到,我用session["FileName"]==null没错误
    如果用.toString()方法的话Session["FileName"]为空无法取值
    先判断下session中是否有值再说
      

  5.   

    if(Session["FileName"]== null) 


    else 


    应该判断这个对象时候为空
      

  6.   


    -----------
    你的应该也会出错吧!!!
    正确答案应该是:
    if(Session["FileName"]== null) 
    {
    }
    else
    {
      

  7.   

    错误 运行不通过 
    session中没值的话如何用toString()方法?
      

  8.   

    应该先判断Session["FileName"] != null 才能ToString()
      

  9.   

    if(Session["FileName"]== null) 


    else 


    先判断一下Session["FileName"]有没有东西,再做其他处理
      

  10.   

    别直接转为string用Session["FileName"]判断