我想使用HttpPostedFile类从网页上传一个或多个大型文件到ASP.NET MVC控制器。使用此类,上传的大于256 KB的文件将缓存到磁盘,而不是保存在服务器内存中。有没有办法使用HttpPostedFile类获取上传进度?
我的理解是,它可以这样做:
if (context.Request.Files.Count > 0)
{
string tempFile = context.Request.PhysicalApplicationPath;
for(int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile uploadFile = context.Request.Files[i];
if (uploadFile.ContentLength > 0)
{
uploadFile.SaveAs(string.Format("{0}{1}{2}",
tempFile,"Upload\\", uploadFile.FileName));
}
}
}
有没有办法定期设置回调,或使用其他一些方法,返回状态通过AJAX或JSON的网页,使进度条和完成百分比可以显示?代码是什么样的?
谢谢我也有这个问题,[见我的问题](http://stackoverflow.com/q/11779751/340045),你知道任何好的教程编写自己的http处理程序? – Ben 2012-08-04 11:51:19