asp.net mvc下文件上传
典型的文件上传表单
<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>");
}
作者:Deep Blue
出处:http://www.cnblogs.com/shenlan/
申明:作者写博是为了总结经验,和以后的工作参考之用。 如需转载,请尽量保留此申明,并在文章页面明显位置给出原文连接。谢谢!
出处:http://www.cnblogs.com/shenlan/
申明:作者写博是为了总结经验,和以后的工作参考之用。 如需转载,请尽量保留此申明,并在文章页面明显位置给出原文连接。谢谢!