我做的下载总是到99%就卡住了,大家帮我看看!

xiaozi151 2011-03-28 12:39:25
byte accessory=dt.Rows[0]["accessory"] as byte[];
Response.Clear();
Response.AddHeader("Content-Disposition","attachment:FileName="+HttpUtility.UrlEncode(dt.Rows[0]["reamark"].ToString(),System.Text.Encoding.UTF8).ToString());
Response.Content="application/octet-stream";
Response.BinaryWrite(accessory);
Response.End();

我用发布到iis7.0上,用localhost网址去用下载没问题,用id去访问,下载总到99%就卡住了。。而且用其他机器访问也是一样,到99%就卡了,请问是我哪里写错了么?
...全文
583 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaozi151 2011-03-28
  • 打赏
  • 举报
回复
改成了Response.Flush(); 还是不行
机器人 2011-03-28
  • 打赏
  • 举报
回复
Response.End();
改为
Response.Flush();
子夜__ 2011-03-28
  • 打赏
  • 举报
回复
#region 文件下载
public bool DownLoadFile(string localPath, string hostURL, int byteCount, string userID, long cruuent)
{

bool result = true;


string tmpURL = hostURL;

byteCount = byteCount * 1024;
hostURL = tmpURL + "&npos=" + cruuent.ToString();

System.IO.FileStream fs;
fs = new FileStream(localPath, FileMode.OpenOrCreate);
if (cruuent > 0)
{
//偏移指针
fs.Seek(cruuent, System.IO.SeekOrigin.Current);
}


System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(hostURL);
if (cruuent > 0)
{
request.AddRange(Convert.ToInt32(cruuent)); //设置Range值
}

try
{
//向服务器请求,获得服务器回应数据流
System.IO.Stream ns = request.GetResponse().GetResponseStream();

byte[] nbytes = new byte[byteCount];
int nReadSize = 0;
nReadSize = ns.Read(nbytes, 0, byteCount);

while (nReadSize > 0)
{
fs.Write(nbytes, 0, nReadSize);
nReadSize = ns.Read(nbytes, 0, byteCount);

}
fs.Close();
ns.Close();
}
catch(Exception ex)
{
LOG.Error("下载" + localPath + "的时候失败!" + "原因是:" + ex.Message);
fs.Close();
result = false;
}


return result;

}
#endregion

langWf 2011-03-28
  • 打赏
  • 举报
回复
if (reader.Read())
{
string filename = reader["ffile"].ToString();
//filename = filename.ToLower() ;
string last = filename.Substring(filename.LastIndexOf('.'));
filename = filename.Substring(0, filename.LastIndexOf('.')) + last;
string ct = "application/octet-stream" ;
if (filename.LastIndexOf(".avi")>0) ct = "video/avi" ; else
if (filename.LastIndexOf(".dot")>0) ct = "application/msword" ; else
if (filename.LastIndexOf(".doc")>0) ct = "application/msword" ; else
if (filename.LastIndexOf(".rtf")>0) ct = "application/msword" ; else
if (filename.LastIndexOf(".exe")>0) ct = "video/x-msdownload" ; else
if (filename.LastIndexOf(".htm")>0) ct = "text/html" ; else
if (filename.LastIndexOf(".html")>0) ct = "text/html" ; else
if (filename.LastIndexOf(".jpg")>0) ct = "image/jpeg" ; else
if (filename.LastIndexOf(".jpeg")>0) ct = "image/jpeg" ; else
if (filename.LastIndexOf(".gif")>0) ct = "image/gif" ; else
if (filename.LastIndexOf(".bmp")>0) ct = "image/bmp" ; else
if (filename.LastIndexOf(".tif")>0) ct = "image/tiff" ; else
if (filename.LastIndexOf(".tiff")>0) ct = "image/tiff" ; else
if (filename.LastIndexOf(".mp3")>0) ct = "video/mp3" ; else
if (filename.LastIndexOf(".mp4")>0) ct = "video/mpeg4" ; else
if (filename.LastIndexOf(".mpg")>0) ct = "video/mpg" ; else
if (filename.LastIndexOf(".mpeg")>0) ct = "video/mpg" ; else
if (filename.LastIndexOf(".png")>0) ct = "image/png" ; else
if (filename.LastIndexOf(".ppt")>0) ct = "application/vnd.ms-powerpoint" ; else
if (filename.LastIndexOf(".swf")>0) ct = "application/x-shockwave-flash" ; else
if (filename.LastIndexOf(".txt")>0) ct = "text/plain" ; else
if (filename.LastIndexOf(".wav")>0) ct = "audio/wav" ; else
if (filename.LastIndexOf(".xls")>0) ct = "application/vnd.ms-excel" ; else
if (filename.LastIndexOf(".xlm")>0) ct = "text/xml" ;

Response.Buffer = true;//
Response.Clear();//
Response.ContentType=ct ;///"application/octet-stream";
//Response.Charset = "'utf-8'" ;
//Response.ContentEncoding = System.Text.Encoding.Unicode ; // .UTF8 ;
int i = filename.LastIndexOf(".") ;
string ext = "" ;
if (i>0)
{
ext = filename.Substring(i) ;
filename = filename.Substring(0,i) ;
} ;
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) ;
filename = filename+ext ;
Response.AddHeader("Content-Disposition", "inline;attachment;filename=\"" + filename + "\"");

//Response.AddHeader("Content-Length", reader["da_size"].ToString());
Byte[] b = (Byte[])reader["fcontent"];

Response.AddHeader("Content-length", Convert.ToString(b.Length));
if (b.Length == 0)
{
Byte[] b2 = { Byte.Parse("32") };
Response.BinaryWrite(b2);
}
else
{
Response.BinaryWrite(b);
}
Response.Flush();
Response.End();
} ;
reader.Close();
机器人 2011-03-28
  • 打赏
  • 举报
回复
byte[] accessory =dt.Rows[0]["accessory"] as byte[];
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;FileName="+HttpUtility.UrlEncode(dt.Rows[0]["reamark"].ToString(),System.Text.Encoding.UTF8).ToString());

Response.AddHeader("Connection", "Keep-Alive");
Response.AddHeader("Content-Length", accessory.Length.ToString());
Response.Content="application/octet-stream";
Response.BinaryWrite(accessory);
Response.End();

xiaozi151 2011-03-28
  • 打赏
  • 举报
回复
刚发现,下载一下子就99%了,但是过N长时间后才下载完成,下载框下显示“ smartscreen 暂时不可用”。

62,074

社区成员

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

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

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

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