标签:
文件下载,先获取文件的路径,在通过招到文件的存放地址,通过return File(path, "text/plain", Url.Encode(name));,可以直接下载,但是必须要修改返回数据类型"text/plain"
//
/// <summary>
/// 文件下载
/// </summary>
/// <returns></returns>
[ActionName("DowLoad")]
public ActionResult DowLoad()
{
string file = Request["accessory"];
string name = null;
string path = null;
//string path = Server.MapPath(file);
path = Path.Combine(Request.MapPath("~/Content/UploadFile"), file);
name = Path.GetFileName(path);
//图片下载
//return File(path, "iamge/jpeg");
// 保证word文档,Excel表格和txt文档格式
//保证文件名称为中文
// byte[] data = Encoding.UTF8.GetBytes(name);
// return File(data, "1", Url.Encode(name));
return File(path, "text/plain", Url.Encode(name));
}
标签:
原文地址:http://www.cnblogs.com/louby/p/4652234.html