如何实现下载功能
asp.net吧
全部回复
仅看楼主
level 1
墨魔方 楼主
期末大作业想做一个音乐网站,请问怎么才能在网页中实现音乐的下载呢?
求大神解答。
2015年05月13日 11点05分 1
level 1
找链接
2015年05月13日 11点05分 2
level 7
图片来自:cushaw95的百度相册
有上传和下载的源码
2015年05月25日 08点05分 4
level 5
#region 根据路径下载文件,主要用于生成的文件的下载+DownloadFile()
/// <summary>
/// 根据路径下载文件,主要用于生成的文件的下载+DownloadFile()
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public ActionResult DownloadFile()
{
string file = Request.QueryString["file"];
string realPath = Server.MapPath("~/" + file);
if (System.IO.File.Exists(realPath))
{
string saveFileName = Request.QueryString["FileName"];
Response.WriteFile(realPath);
Response.Charset = "GB2312";
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel/msword";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(saveFileName) + "" + System.IO.Path.GetExtension(file));
Response.Flush();
Response.End();
}
return new FileStreamResult(Response.OutputStream, "application/ms-excel/msword");
}
#endregion
2015年05月26日 04点05分 5
level 1
墨魔方 楼主
谢谢各位前辈的指导
2015年07月05日 04点07分 6
1