·我在本地可以上传几M的文件,但放到服务器上后就只能上传几十KB的文件,一旦大于100KB左右,就会报无法访问已关闭的文件...
已经在WEB里加了<httpRuntime maxRequestLength="102400" executionTimeout="60"/>但还是没有用··请高手指教
            HttpFileCollection fileList = Request.Files;
            string attahDir = Server.MapPath("Attahments");
            string userDir = attahDir + "/" + name;
            if (!Directory.Exists(userDir))
            {
                Directory.CreateDirectory(userDir);
            }
            for (int i = 0; i < fileList.Count-1; i++)
            {
                HttpPostedFile file = fileList[i];
                if (file.FileName.Length <= 0 || file.ContentLength <= 0) continue;
                //Attachment attachment = new Attachment(file.FileName);
                size += file.ContentLength;
                string attachname = DateTime.Now.ToString("yyyyMMddHHmmss") + file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1);
                filename = filename + "?" + attachname;
                file.SaveAs(userDir + "/" + attachname);《--这里会报错!无法访问已关闭的文件....
            }
 
 

解决方案 »

  1.   

    上传大小有限制,出异常是正常情况,无非是不让异常影响程序运行罢了。
    可以用try...catch块try
    {
    SaveAs(...);
    }
    Catch
    [
    //输出文件过大的提示
    }
      

  2.   

    一次都成功不了,还是前面的可以成功,后面的成功不了。
    我google的结果:1. 一个页面上传多个文件的话,maxRequestLength要指定总和。
    Just need to take into account if you have three upload fields on one page and want each to be limited to 10 MB you need a maxRequestLength of at least 30 MB to handle it.2. 给服务器上的.net framework打service pack.我也不知道是不是能解决问题。另外executionTimeout="60" 60s是不是有点少啊,在internet上几M文件的传输有可能超过60s的。先设置个大值用来确定是,还是不是这个问题。
      

  3.   

    是这样的··同样的一段程序,我在用VS进行本地测试的时候,可以上传1M大小的文件
    但一旦放到了远程服务器上,就只能上传最大50KB的文件,不然就会报这个错···
    我想应该不是大小和时间的限制吧?因为我测试用的文件才81KB就会报错,而且时间也很短··谢谢各位多多帮忙
      

  4.   

    maxRequestLength="102400"  这个设大些!
      

  5.   

    问:
    如题
    用 System.Web.UI.HtmlControls.HtmlInputFile.PostedFile.SaveAs(filepath);
    将客户端文件上传到服务器上,如果上传页面不关闭,上传到服务器上的文件就不能删除,删除时提示此文件正在使用。要怎么办才能让 SaveAs 后就关闭对上传文件的关连。我用 HtmlInputFile.PostedFile.InputStream.Close();和HtmlInputFile.Dispose();都没有用,急,谢谢!
    ______________________________________________________________________________________________
    答1:
    try (didn' test, so it might not work):System.IO.FileStream fs = new System.IO.FileStream(YourFilePath, FileMode.Create);
    byte[] bs = new byte[YourInput.PostedFile.ContentLength];
    YourInput.PostedFile.InputStream.Read(bs,0,bs.Length);
    fs.Write(bs,0,bs.Length);
    fs.Close();______________________________________________________________________________________________
    答2:
    建议用 Request.Files 方式来接受文件。这样自己容易控制。
    ______________________________________________________________________________________________
    答3:
    多谢两位,两个方法都试了,可都还是不能删除?还有办法嘛?
    ______________________________________________________________________________________________
    答4:
    Sorry,是我搞错了,可以删除,我上传完了又有一次对文件的引用没有释放。可以删除的,谢!结贴。
    ______________________________________________________________________________________________
    答5:
    Sorry,我搞错了,可以删除的,我上传完了又对文件引用了一次,没有释放。多谢!结贴。
      

  6.   


    写入的权限肯定是有的····但我现在不是关不掉··而是消失的太早了··让我无法保存·我用的HttpPostedFile类