典型的文件上传表单

<form action="/File" enctype="multipart/form-data"

method="post"/>

<input type="file" name="file" />

<input type="submit" name="upload" value="提交" />

</form>

文件上传操作

public ActionResult Index(HttpPostedFileBase file)

if (file != null)
{
               
     string strpath = Server.MapPath("~/files/"+ file.FileName);
     //获取文件路径
     if (file.FileName.LastIndexOf(@"\") > 0)
     {
          strpath = Server.MapPath("~/files/"+ file.FileName.Substring(file.FileName.LastIndexOf(@"\")));
     }
     file.SaveAs(strpath);//把图片保存在此路径中
     return Content("<script>alert('上传文件成功!');location.href='" + Url.Content("~/File") + "'</script>");
}

最新文章

  1. Nginx实现多域名证书HTTPS
  2. 正则表达式入门(六)匹配unicode和其他字符
  3. [课程设计]Scrum团队分工及明确任务1.0 ----多鱼点餐
  4. Chrome: Resource interpreted as Font but transferred with MIME type font/x-woff
  5. Linux线程的实现 &amp; LinuxThread vs. NPTL &amp; 用户级内核级线程 &amp; 线程与信号处理
  6. java单元测试(使用junit)
  7. jquery中onclick内$(this)指向
  8. js django 数据互动
  9. 渗透测试入门DVWA 教程1:环境搭建
  10. webkit
  11. Sql Server 获取存储过程或函数创建语句
  12. JSP——文件上传
  13. 第六周助教工作总结——NWNU李泓毅
  14. leetcode-66.加一
  15. Ajax之Jquery封装使用举例2(Json和JsonArray处理)
  16. 超图不支持JPEG格式的WMTS服务
  17. java 数组(一)
  18. SQL Server 2016 发送邮件功能
  19. SpringBoot -- 事件(Application Event)
  20. 统计代码执行时间,使用Stopwatch和UserProcessorTime的区别

热门文章

  1. hdu4185解题报告
  2. wust 1061 链表的合并
  3. Jalopy 之 HelloWorld —— Jalopy 在 MyEclipse 下的安装与使用
  4. Java-HTTP连接时如何使用代理(一)—— System.Property方式
  5. YTU 2620: B 链表操作
  6. UVA 11427 Expect the Expected (期望)
  7. java生成带html样式的word文件
  8. jsonp从服务器读取数据并且予以显示
  9. WP7 MD5加密
  10. Win8环境下 IIS6部署MVC网站出现的无法显示此网页错误