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