HttpFileCollection hfc = Request.Files;
if (hfc.Count > 0)
{
FileStream fs;
Stream _stream;
int btLen = 10000;
byte[] _byte = new byte[btLen];
int len, ysc = 0;
string _root = Server.MapPath("~");
HttpPostedFile hpf;
foreach (string str in hfc)
{
hpf = hfc[str];
if (hpf.ContentLength > 0)
{
fs = new FileStream(_root + "/" + hpf.FileName, FileMode.Create);
_stream = hpf.InputStream;
len = _stream.Read(_byte, 0, btLen);
while (len > 0)
{
ysc += len;
fs.Write(_byte, 0, len);
len = _stream.Read(_byte, 0, btLen);
}
_byte = null;
hpf = null;
_stream.Close();
_stream = null;
fs.Close();
fs = null;
}
}
}
//实时获取 根据ysc和hpf.ContentLength计算上传进度