日期:2014-05-18  浏览次数:20468 次

关于文件下载的问题(C#)
手机拍摄的一些视频,想放到自己的网站上,供同学和朋友们下载
试了几种方法总不成功,向大家请教

 <a href="<%=视频1的路径%>">视频1</a>
文件的路径没有问题
点击的时候总是提示找不到网页
而图片就没有问题

用Response.BinaryWrite的方法也不成功
string strFilePath = this.MapPath("") + "\\Image\\000.3gp";
//this.Response.Write(strFilePath);
Stream sr = File.Open(strFilePath,FileMode.Open);
this.Response.BinaryWrite(sr);
提示我的使用的BianryWrite方法参数无效



------解决方案--------------------
string strPath = "视频1的路径";

strPath = Server.MapPath(strPath);
Response.Expires = 0;

string FileName = "视频的文件名";
if (FileName == null || FileName.Length <= 0 && System.IO.File.Exists(strPath + Server.UrlDecode(FileName)))
{
Response.Write("<script>window.opener=null;window.close();</script>");
Response.End();
}

FileName = Server.UrlDecode(FileName);
Response.Clear();
 
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(FileName));

Response.TransmitFile(strPath + FileName);
------解决方案--------------------
顶楼上的