mvc中文件上传下载

//控制器

public ActionResult FileUpLoad(HttpPostedFileBase f1)
{
string path = Server.MapPath("~/Picture");
string filename = Path.Combine(path,f1.FileName);
f1.SaveAs(filename);
return Content("OK");
}
public ActionResult FileDownLoad()
{
string path = Server.MapPath(@"C:\Users\Administrator\Desktop\自己练习\上传下载\UpLoad\UpLoad\Picture\QQ图片20190228155326.png");
FileStream fs = new FileStream(path,FileMode.Open);
return File(fs,"text/plain","a.jpg");
}

//视图

<body>
<div>
<form action="/Demo/FileUpload" enctype="multipart/form-data" method="post">
<input id="f1" type="file" name="f1" />
<input id="Submit1" type="submit" value="上传" />
</form>
<a href="#/Demo/FileDownLoad">下载</a>
</div>
</body>
上一篇:90 % Java 程序员被误导的一个性能优化策略


下一篇:ldap数据库--ODSEE--suffix