用stream模式下载大文件是遇到的问题?

xinxincao 2004-01-11 02:01:40
1。由于文件比较大(一两百兆),所以要分成很多次来读写,但是除了打了SP1的IE6外,其他版本的浏览器都不认识Response.IsClientConnected,现象是用左键电击下载连接,点到保存路径对话框或已经开始下载后,再点取消,之后再重复之前的操作,到第三次时,程序不在有任何反映,必须把页面关掉重来才可以,但用下载工具下载不存在上述问题
2。下载之后的内存回收问题,我的代码现在不执行回收工作,请高手指教怎么改?
3。URL中没有给出文件路径(为了安全),现在的问题是用FLASHGET下载时显示的文件名是页面的名称,有没有办法控制下载工具中显示的文件名

我的代码如下:
//下载文件
private void Download()
{
Stream iStream=null;

if (!System.IO.File.Exists(FilePath))
{
ErrorInfo="Sorry,系统找不到您要下载的文件!";
return;
}
try
{
iStream= new FileStream(FilePath, System.IO.FileMode.Open,
FileAccess.Read,FileShare.Read);
if (this.StartPoint>0)
iStream.Seek(this.StartPoint,SeekOrigin.Begin );

FileLength=iStream.Length;
long ByteToRead = FileLength-this.StartPoint ;
// string FileName = "File"+FileID.ToString().Trim()+".wmv";
FileInfo fileinfo = new FileInfo(FilePath);
String FileName = fileinfo.Name;

try
{
int n = FileName.IndexOf('(');
int m = FileName.IndexOf(')');
int x = Convert.ToInt32(FileName.Substring(n+1,m-n-1));
FileName = FileName.Substring(0,n) + "--" + "第" + x + "集" + ".wmv";
}
catch
{
}

Response.Clear();
// Response.ContentType = "application/ms-download";
Response.ContentType = "video/wmv";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8));

Response.AddHeader("Content-Length", ByteToRead.ToString());
Response.Flush();

this.WriteLogInfo(DateTime.Now.ToString() +" OK--------- 下载文件 " + FilePath +" 开始 "+ " DownloadID= " + DownloadID.ToString());

byte[] Buffer;
int BufferLength=Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["BufferLength"]);
// byte[] Buffer = new byte[BufferLength];
// byte[] Buffer = new byte[iStream.Length];
int Len=1;
Length1=Length2=0;
SleepInterval=1500;

Aborted=ClientClosed=EndOfFile=false;
// this.DBObj.UpdateDBOnBeginDownload(DownloadID,UserIP,ServerIP,DateTime.Now,out ErrorInfo);
this.CheckTimer.Enabled=true;
// while (!this.CanStopDownload(Aborted,ClientClosed,EndOfFile))
while (Len>0 && ClientClosed==false)
{
Buffer= new Byte[BufferLength];
Len = iStream.Read(Buffer, 0, BufferLength);
// if (Len>0)
// {
Response.OutputStream.Write(Buffer,0,Len);
Response.Flush();
// System.Threading.Thread.Sleep(SleepInterval);
// }
Length2+=Len;
// EndOfFile=Len<=0L;
ClientClosed=!this.Response.IsClientConnected;
// iStream.Read(Buffer,0,(int)iStream.Length);
//// Response.Clear();
// Response.BinaryWrite(Buffer);
// Response.Flush();
// Response.Clear();
}
iStream.Close();
iStream = null;
Response.End();
...全文
119 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pangming051380 2004-04-12
  • 打赏
  • 举报
回复
up
xinxincao 2004-01-11
  • 打赏
  • 举报
回复
这个帖子的代码太乱了,可以到下面这个帖子回答我的问题,谢谢
http://expert.csdn.net/Expert/topic/2653/2653967.xml?temp=.2744104

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧