日期:2014-05-20  浏览次数:20774 次

下载代码运行奇慢,为什么啊?
private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
System.IO.FileStream   r   =   new   System.IO.FileStream( "e:/后缀.txt ",   System.IO.FileMode.Open);  
Response.Buffer   =   false;  
Response.AddHeader( "Connection ",   "Keep-Alive ");  
Response.ContentType   =   "application/octet-stream ";  
Response.AddHeader( "Content-Disposition ",   "attachment;filename= "   +   System.IO.Path.GetFileName( "e:/后缀.txt "));  
Response.AddHeader( "Content-Length ",   r.Length.ToString());  
while   ((true))  
{  
byte[]   Buffer   =   new   byte[1024];  
Int64   leng;  
leng   =   r.Read(Buffer,   0,   1024);  
if   (leng   ==   0)  
{  
goto   exitWhileStatement0;  
}  
if   ((leng   ==   1024))  
{  
Response.BinaryWrite(Buffer);  
}  
else  
{  
byte[]   b   =   new   byte[leng];  
Int64   i;  
for   (i   =   0;   i   <=   leng;   i++)  
{  
b[i]   =   Buffer[i];  
}  
Response.BinaryWrite(b);  
}  
}  
exitWhileStatement0:   ;  
r.Close();  
File.Delete( "e:/后缀.txt ");
}

------解决方案--------------------
你是在本机调试的吗/
注意缓冲数组的分配问题