关于下载的一个问题 <a href="down.aspx?id=324">下载文件</a>点击这个连接后会打开down.aspx文件,通过后台程序找到要下载的文件(已解决)后弹出下载对话框,同时关掉down.aspx文件,只剩下下载对话框例如BTBBT的种子下载http://bbs.btbbt.com/attachpage.php?aid=530070 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 set :conenttype = application/octet-stream string pathfile = @"D:\需求说明书1.doc";//需要下载的文件 FileStream fs = new FileStream(pathfile, FileMode.Open, FileAccess.Read); long p = 0; FileInfo fi = new FileInfo(pathfile); long l = fi.Length; if (Request.Headers["Range"] != null) { Response.StatusCode = 206; p = long.Parse(Request.Headers["Range"].Replace("bytes=", "").Replace("-", "")); } Response.AddHeader("Content-Length", ((long)(l - p)).ToString()); if (p != 0) { Response.AddHeader("Content-Range", "bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString()); } Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pathfile)); fs.Position = p; int i = 1; byte[] b = new Byte[1024]; while (i > 0) { i = fs.Read(b, 0, b.Length); Response.OutputStream.Write(b, 0, i); } fs.Close(); Response.End(); Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pathfile));--> Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name)); xiaotupansy(分基本靠接)成功下载,不过下载对话框上的吧服务端文件物理路径也写出来了。能在隐藏吗? xiaotupansy(分基本靠接)按你下面的说明可以实现了,但是和bt之家那个还是有点不一样。需要点保存的时候down.aspx才能关闭,不能电完连接就关闭吗?在一个,这段代码支持任意文件格式和大小吗? xiaotupansy(分基本靠接)上一个问题也已经解决,怎么解决中文乱码问题??? HttpUtility.UrlEncode(fi.Name))这一行就是用来解决中文乱码的啊,这是我知道的最简单的代码了 需正则表达式一句 使用Signal进行web聊天问题 急急急 请教一个XML问题 javascript怎么样添加、删除一段HTML代码? C# Replace替换字符的问题 已有PHP程序,要改成ASP.NET有多难 为什么我有文本编辑器的页面不能被访问? [关于乱码]我有两个站点,一个是用gb2312,还有一个utf-8 为什么打开项目后,文件名旁边就有个*符号??? 为何本地调试没问题,服务器上调试不行?在线等待 GridView与下拉菜单选择数据的问题 请教!!!ASP.NET+IIS的问题!!!(急!!!)(在线等!!!)
FileStream fs = new FileStream(pathfile, FileMode.Open, FileAccess.Read);
long p = 0;
FileInfo fi = new FileInfo(pathfile);
long l = fi.Length;
if (Request.Headers["Range"] != null)
{
Response.StatusCode = 206;
p = long.Parse(Request.Headers["Range"].Replace("bytes=", "").Replace("-", ""));
} Response.AddHeader("Content-Length", ((long)(l - p)).ToString());
if (p != 0)
{
Response.AddHeader("Content-Range", "bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString());
} Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pathfile));
fs.Position = p; int i = 1;
byte[] b = new Byte[1024];
while (i > 0)
{
i = fs.Read(b, 0, b.Length);
Response.OutputStream.Write(b, 0, i);
} fs.Close();
Response.End();
上一个问题也已经解决,
怎么解决中文乱码问题???
这一行就是用来解决中文乱码的啊,这是我知道的最简单的代码了