前端: <form id="form" method="post" action="/Attachment/Save/" enctype="multipart/form-data" > <table> <tr> <td> 上传文件: </td> <td> <input id="FileNamePath" required="true" name="FileNamePath" type="file" />(注:选择图片文件) </td> </tr> </table> </form>
这里要特别注意:enctype="multipart/form-data",否则后台无法获取到
后端:
string fileExtension = string.Empty; ;
string filename = string.Empty; ;
string filePathName = string.Empty;
long fileSize = 0;
if (Request.Files["FileNamePath"].ContentLength>0)
{
string path = Server.MapPath(ConfigHelp.GetAppSettings("ADImage"));
string uploadFileName = Path.GetFileName(Request.Files["FileNamePath"].FileName);
fileExtension = System.IO.Path.GetExtension(Request.Files["FileNamePath"].FileName).ToLower();
filename = entity.Title + fileExtension;
filePathName = Path.Combine(path, filename);
Request.Files["FileNamePath"].SaveAs(filePathName);
fileSize = Request.Files["FileNamePath"].ContentLength;
}
多个文件时后台的获取方式为:
foreach(string name in Request.Files)
{
Request.Files["name"]
}
这里的name是前台标签input的name
专注写好每一篇精品博文的热情离不开您的肯定与支持
您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】按钮。
如果你想及时关注到工作流引擎相关博文,请继续关注我的后续博客,不妨点击正下面【关注我】
您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】按钮。
如果你想及时关注到工作流引擎相关博文,请继续关注我的后续博客,不妨点击正下面【关注我】
版权声明:本文原创发表于 博客园,作者为 F2BPM工作流引擎 转载时未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则视为侵权。
浙公网安备 33010602011771号