之前发过一帖http://topic.csdn.net/u/20110916/15/570124a9-267a-49bb-9181-477765a1e1c7.html[AjaxPro.AjaxMethod]
        public string IsChunzai(string filname)
        {                 bool ss = System.IO.File.Exists(Server.MapPath("~/Files/") + filname);            if (ss)
            {
                return "1";
            }else
            {
               return "2";
            }
            
        }这个就是上传文件的时候判断是否有重名,我在前台调用了一次后,没什么,再上传第2个文件时,就报错了。报的错是"xx未定义"我想是不是System.IO.File.Exists(Server.MapPath("~/Files/") + filname);
后未释放资源,调用   this.Dispose();也无反应,请教下大大们。

解决方案 »

  1.   


    filname=Server.MapPath("~/Files/") + filname;if (File.Exists(filname))
    {
       return "1";}
    else
      {
      return "2";
      }
        
    这样试下
      

  2.   

    你上传文件与js判断是同一个页面么?如果是应该是没有权限,当文件上传的form提交后,再进行js操作肯定都会报错。
      

  3.   


    是的,同一个页面,所以我现在用了一个方法先暂时解决了。 Response.Write("<script>alert('上传成功');window.location.href='WebForm1.aspx';</script> ");就是刷新下浏览器,但是总觉得不太好。
      

  4.   


    为什么当文件上传的form提交后,就没权限了呢?
      

  5.   

    作为过来人,提醒你一句,不要这样alert。
    Response.Write("<script>alert('上传成功');window.location.href='WebForm1.aspx';</script> ");
    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('helloWorld');window.location.href='webform1.aspx'</script>");
      

  6.   

      [AjaxPro.AjaxMethod]
      public string IsChunzai(string filname)
      {
          bool ss = System.IO.File.Exists(Server.MapPath("~/Files/") + filname);
          return ss ? "1" : "2";
      }看下JS
      

  7.   

    $(document).ready(function(){ 
          $("#Button1").click(function(){
                 var file=$("#<%=FileUpload1.ClientID%>").val();
                 if(file.length == 0){alert('请先选择一个文件');return false;}
                 $.ajax({
                        url: 'Handler1.ashx',
                        type: 'Post',
                        data: { id: file.substring(file.lastIndexOf("\\") + 1)},
                        success: function (){
                        if(data=="1"){
                             var msg = confirm("文件已存在,是否覆盖?");
                             if(!msg) return false; 
                             //(e || window.event).returnValue = false;
                        }
                        return true;
                 });
          });
    });