.NET MVC 文件上传下载
来源:互联网 发布:java项目中的角色 编辑:程序博客网 时间:2024/06/05 23:50
public class FileController : Controller
{
//
// path: /File/Upload
public ActionResult Upload() {
ActionResult result = View("UploadFile");
HttpPostedFileBase uploadFile = Request.Files["upload"];
if(null != uploadFile){
string filePath = uploadFile.FileName;
string fileName = Path.GetFileName(filePath);
string uploadPath = HttpContext.Server.MapPath("../Upload/")+fileName;
uploadFile.SaveAs(uploadPath);
return RedirectToAction("ListFiles", "File");
}
return result;
}
public ActionResult ListFiles() {
string filePath = Server.MapPath("../Upload");
string[] fileNames = Directory.GetFiles(filePath);
for (int i = 0; i < fileNames.Length;i++ )
{
fileNames[i] = Path.GetFileName(fileNames[i]);
}
ViewData["fileNames"] = fileNames;
return View("ListFile");
}
public ActionResult Down(string fileName)
{
//文件下载
string fn = Request.Url.ToString();
string filePath = Server.MapPath("../../Upload")+"\\"+fileName;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8));
// Response.AppendHeader("Content-Length", fInfo.Length.ToString());
Response.WriteFile(filePath);
return null;
}
}
- .NET MVC 文件上传下载
- Spring MVC 文件上传下载
- spring mvc 文件上传下载
- Spring MVC 文件上传下载
- Spring MVC-文件上传下载
- Spring MVC 文件上传下载
- spring mvc文件上传下载
- Spring MVC 文件上传下载
- Spring MVC 文件上传下载
- Spring MVC 文件上传下载
- 【译】利用Asp.net MVC处理文件的上传下载
- 利用Asp.net MVC处理文件的上传下载
- 利用Asp.net MVC处理文件的上传下载
- 利用Asp.net MVC处理文件的上传下载
- AWS S3 API实现文件上传下载(ASP.NET MVC)
- asp.net 上传下载文件
- ASP.NET文件上传下载
- Asp.net 文件上传下载
- web.xml中<context-param>的作用,及与init-param区别
- 数据结构-----1的数目
- 递归列出指定目录下的所有文件的绝对路径
- 检索COM类工厂中CLSID为{000209FF-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005
- 各种标签引用
- .NET MVC 文件上传下载
- 【HDU 1247】字典树 一个单词由两个单词组成
- 搜索指定目录下是否存在某个文件
- Servlet生命周期与工作原理
- JavaScript 思考总结(一)JavaScript是什么
- 数据库语言
- [LeetCode] Combinations [38]
- gflags摘记
- FPGA学习的一些误区