·我在本地可以上传几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);《--这里会报错!无法访问已关闭的文件....
}
已经在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);《--这里会报错!无法访问已关闭的文件....
}
解决方案 »
- 如何在FrontPage中改变DataList显示长度?
- asp.net 生成xml问题求解!!!
- dataview的筛选
- 里面有一个vbscript的脚本,请高手帮我改成js的,谢谢啊!
- [求助]~~在ASP.NET里面怎么实现“退出系统”?~~~~
- asp.net中一readline()问题!
- 我要动态地往一个RadioButtonList中添加RadioButton该怎么写代码?
- 求源代码
- 我在GridView使用它自带的分页功能,有几个问题:
- 新人求助
- 请大家说说Linq的缺点
- asp.net C# webservice 在本机发布到IIS可以,但是发布至史一个服务器就不能运行.请高手来解.谢谢
可以用try...catch块try
{
SaveAs(...);
}
Catch
[
//输出文件过大的提示
}
我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的。先设置个大值用来确定是,还是不是这个问题。
但一旦放到了远程服务器上,就只能上传最大50KB的文件,不然就会报这个错···
我想应该不是大小和时间的限制吧?因为我测试用的文件才81KB就会报错,而且时间也很短··谢谢各位多多帮忙
如题
用 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,我搞错了,可以删除的,我上传完了又对文件引用了一次,没有释放。多谢!结贴。
写入的权限肯定是有的····但我现在不是关不掉··而是消失的太早了··让我无法保存·我用的HttpPostedFile类