Controller层调用类
[HttpGet]
public HttpResponseMessage UploadAndDownload()
{
//文件上传到服务器上的根目录
string root = System.Web.Hosting.HostingEnvironment.MapPath(@"~/upload");
string fileName = "测试.docx";
//解析文件在服务器上的上传路径
string path = FileHelper.transPath(fileName, root);
//获取要上传的文件
var files = HttpContext.Current.Request.Files;
HttpPostedFile file = HttpContext.Current.Request.Files[0];
//保存文件
file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
//下载word文件
return FileHelper.download(fileName, path);
}
view层:
<a href="http://localhost:60179/api/CeshiController/UploadAndDownload" rel="external nofollow" "> 导出 </a>
希望本文所述对大家C#程序设计有所帮助。
注:相关教程知识阅读请移步到c#教程频道。










