level 1
期末大作业想做一个音乐网站,请问怎么才能在网页中实现音乐的下载呢?
求大神解答。
2015年05月13日 11点05分
1
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