在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
前端: <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) 这里的name是前台标签input的name |
请发表评论