081223 asp写2进制文件。

来源:互联网 发布:网络常见端口号 编辑:程序博客网 时间:2024/05/01 19:04

var totalBytes = Request.TotalBytes;

var BinForm = new ActiveXObject( "ADODB.Stream");
    BinForm.Type=1;
    BinForm.Open();
    var nBlockSize = 1024*8;
    var nWriteTimes = totalBytes/nBlockSize;  //这里是浮点的
    var nLeft = totalBytes%nBlockSize;
    nWriteTimes = Math.floor( nWriteTimes );//取整数
    for( var i=0; i< nWriteTimes; ++i )
    {
        BinForm.Write( Request.BinaryRead(nBlockSize) );
    }
    if( nLeft >0 )
        BinForm.Write( Request.BinaryRead(nLeft) );
    BinForm.SaveToFile( Server.MapPath( filename) ,2   );           
    BinForm.Close();