1.上传图片 前台:form中加入 enctype="multipart/form-data"。一般处理事件中 context.Request.ContentType = "text/html"; 案例: HttpFileCollection files = HttpContext.Current.Request.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { HttpPostedFile postFile = files["upImage"]; string fileName, fileExtension; string pictureName = HrInfoModel.UserCode; string path = "~\\upfiles\\imgs\\"; fileName = System.IO.Path.GetFileName(postFile.FileName); if (fileName != "") { fileExtension = System.IO.Path.GetExtension(fileName); if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png") { postFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path + pictureName + fileExtension)); string lookPath = "upfiles\\imgs\\"; HrInfoModel.Photo = lookPath + pictureName + fileExtension; break; } } } }
转载于:https://www.cnblogs.com/slcc/archive/2012/07/17/2594836.html