下载功能 请问怎样用C#写一个下载功能? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FileInfo Fi = new FileInfo(filePath);if (Fi.Exists){ FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=1.excel"); Response.BinaryWrite(bytes); Response.Flush(); Response.End();} //提供下载的文件,不编码的话文件名会乱码 private string fileName = HttpContext.Current.Server.UrlEncode("陈百强-一生何求.mp3"); private string filePath = HttpContext.Current.Server.MapPath("~\\Music\\陈百强-一生何求.mp3"); //使用TransmifFile下载文件 protected void Button1_Click(object sender, EventArgs e) { FileInfo info = new FileInfo(filePath); long fileSize = info.Length; Response.Clear(); Response.ContentType = "application/x-zip-compressed"; Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); //不指明Content-Length用Flush的话不会显示下载进度 Response.AddHeader("Content-Length", fileSize.ToString()); Response.TransmitFile(filePath, 0, fileSize); Response.Flush(); Response.Close(); } 以上两种方法如果被迅雷抓到,下载的会是当前的HTML页面不知各位大侠有解决办法没? 父路径能打开,完整路径打不开 jquery实现固定表头 MVC下一个Cookie使用问题求助. 求助:GridView绑定ArrayList 求救!求救!在.net下嵌入的dll文件中读取数据库权限问题 ASP.NET操纵数据库的语句! ◆◆◆◆◆◆◆◆◆紧急发问:关于js下对输入长度验证的问题 新闻内容分页.. 关于 TreeNode 的 setAttribute的方法 网站发布后,其他电脑访问不了。咋回事? 关于博客的跳转问题 .net 中怎么获得gridview的headtext值
if (Fi.Exists)
{
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=1.excel");
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
private string fileName = HttpContext.Current.Server.UrlEncode("陈百强-一生何求.mp3");
private string filePath = HttpContext.Current.Server.MapPath("~\\Music\\陈百强-一生何求.mp3");
//使用TransmifFile下载文件
protected void Button1_Click(object sender, EventArgs e)
{
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath, 0, fileSize);
Response.Flush();
Response.Close();
}