我在后台写 this.file1.PostedFile.ContentLength < 10000000   用来控制上传文件大小 可是这种方法是在我把文件上传到服务器后 才开始判断大小的 文件小的还可以判断  当文件比较大的时候 页面会死 这种情况怎么解决阿  能不能在没有把文件上传到服务器前的时候 就判断大小阿  或者传到服务器后再判断文件大小 如果超过限制 再删除它 可是这种情况页面怎么会不死啊
 我也上网搜了很多  可是回复都是讲大框的 希望能提供具体的方法   

解决方案 »

  1.   

    很多可以实现,不过基于安全考虑,浏览器默认都是禁止使用的。如果是大众化的网站或者程序,那还是自己做ActiveX吧。
      

  2.   

    上传前判断要用到activex,否则你是没权限判断的.参考:
    <HTML><HEAD>         
          <SCRIPT>         
                    
          function       getFileSize       (fileName)       {         
                    
          if       (document.all)       {         
          window.oldOnError       =       window.onerror;                         
          window.onerror       =       function       (err)       {         
          if       (err.indexOf('utomation')       !=       -1)       {         
          alert('没有访问文件的权限');                                         
          return       true;                                 
          }                             
          else             
          return       false;                         
          };         
                          var       fso       =       new       ActiveXObject('Scripting.FileSystemObject');         
                          var       file       =       fso.GetFile(fileName);                         
          window.onerror       =       window.oldOnError;         
                          return       file.Size;           }}         
          </SCRIPT>         
          </HEAD>         
          <BODY>         
          <FORM       NAME="formName"><INPUT       TYPE="file"       NAME="fileName"><BR>         
          <INPUT       TYPE="button"       VALUE="查看文件字节大小"         
        
      ONCLICK="alert(getFileSize(this.form.fileName.value))"><BR>         
          </FORM></BODY>         
          </HTML>     
      

  3.   

    IE都话 可以这样
    function getFileSize(filePath)   
    {   
       var fso = new ActiveXObject("Scripting.FileSystemObject");   
       return fso.GetFile(filePath).size;   
      

  4.   

    图片的话 可以这样
    function getFileSize(filePath)
    {
       var image=new Image();
       image.dynsrc=filePath;
       return image.fileSize;
    }
      

  5.   

    web.config内: <httpRuntime executionTimeout="300" maxRequestLength="10240"/>
    </system.web>executionTimeout设置超时秒数
    maxRequestLength允许大小:kb
      

  6.   

    <httpRuntime executionTimeout="设置超时秒数" maxRequestLength="允许大小"/> 
    </system.web>
      

  7.   


    不是告诉你了吗..要在上传前判断大小,只能用activex,否则判断不了.
    参看2,3楼代码.
      

  8.   

    maxRequestLength  允许上传文件大小  单位kb 
      

  9.   

    下面的代码供你参考一下,你可以自己改成aspx页面里能用的方式<html>   
    <head>   
    <title>客户端控制上传图像大小</title>   
    <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">   
    </head>   
    <body>   
    <SCRIPT   LANGUAGE="JavaScript">   
    <!--   
    var   FileMaxSize   =   50;//限制上传的文件大小,单位(k)   
    function   chkform(){   
    if(document.HwForm.Photo.value==""){
    alert("请选择照片");
    document.HwForm.Photo.focus();
    return   false;
    }   
    if(document.HwForm.PhotoFileSize.value<=0){
    alert("请重新选择照片");
    document.HwForm.Photo.focus();
    return   false;
    }   
    if(document.HwForm.PhotoFileSize.value>FileMaxSize*1024){
    alert("选择的照片超过"+FileMaxSize+"K,请重新选择");
    document.HwForm.Photo.focus();
    return   false;}   
    alert("可以提交,当前为测试");return   false;   
    }   
    //-->   
    </SCRIPT>   
    <form   method="POST"   name="HwForm"   onsubmit="return chkform();"   enctype="multipart/form-data">   
    照片(请选择一个50K以内的图片文件):<input   type="file"   name="Photo"   onpropertychange="if(document.HwForm.Photo.value!=''){document.getElementById('PhotoImg').src=document.HwForm.Photo.value;}"/>
    <IMG   style="POSITION:   absolute;   TOP:  100px;left:0px;"   onerror="document.all.PhotoFileSize.value='-1';alert('请选择一个图像文件');"   onload="if(document.getElementById('PhotoImg').fileSize<=1024*FileMaxSize){document.all.PhotoFileSize.value=document.getElementById('PhotoImg').fileSize;}else{alert('图片不能大于'+FileMaxSize+'K,请重新选择');document.all.PhotoFileSize.value='-1';}" style="display:none"  id="PhotoImg">
    <input   size="3"   type="hidden"   name="PhotoFileSize"   value="-1"   />   
    <input   type="submit"   value="提交">   <input   type="reset"   value="重置">     
    <input type="button" onclick="alert(document.getElementById('PhotoImg').fileSize)"/>
    </form>   
    </body>   
    </html>
      

  10.   

    <system.web>
    <httpRuntime maxRequestLength="40690"
             useFullyQualifiedRedirectUrl="true"
             executionTimeout="6000"
             useFullyQualifiedRedirectUrl="false" 
         minFreeThreads="8" 
         minLocalRequestFreeThreads="4" 
          appRequestQueueLimit="100" 
          enableVersionHeader="true"
             />
    </system.web>

    http://www.cnblogs.com/wwyup/articles/1066522.html