protected void Unnamed1_Click(object sender, EventArgs e) { UploadFile uf = new UploadFile(); /*可选参数*/ uf.SetIsUseOldFileName(true); //是否使用原始文件名作为新文件的文件名(默认:true),true原始文件名,false系统生成新文件名 uf.SetFileDirectory(Server.MapPath("/Form/temp/")); //文件保存路径(默认:/upload) uf.SetFileType("*"); //允许上传的文件类型, 逗号分割,必须全部小写! *表示所有 (默认值: .pdf,.xls,.xlsx,.doc,.docx,.txt,.png,.jpg,.gif ) uf.SetIsRenameSameFile(false); //重命名同名文件? //文件以时间分目录保存 var message = uf.Save(Request.Files["Fileupload1"]); // “/file/temp3/2015/4/xx.jpg” //文件以编号分目录保存 var message2 = uf.Save(Request.Files["Fileupload1"], "001" /*编号*/); // “/file/temp3/001/xx.jpg” //返回信息 var isError = message.Error; //判段是否上传成功 var webPath = message.WebFilePath; //返回web路径 var msg = message.Message; //返回上传信息 var filePath = message.FilePath; //反回文件路径 var isSuccess = message.Error == false; }
public string UploadFile() { UploadFile ui = new UploadFile(); ui.SetMaxSizeM(5); ui.SetFileType(".docx,.txt,.doc,.jpg,.gif,.xls,.xlsx");//配在webConfig中 string saveFolder = "/areas/formcontrol/views/_upload/temp/file/"; ui.SetFileDirectory(saveFolder); HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0]; var reponseMessage = ui.Save(file); return (reponseMessage).ModelToJson(); }
public string UploadFile() { UploadFile ui = new UploadFile(); ui.SetMaxSizeM(5); ui.SetFileType(".docx,.txt,.doc,.jpg,.gif,.xls,.xlsx");//配在webConfig中 string saveFolder = "/areas/formcontrol/views/_upload/temp/file/"; ui.SetFileDirectory(saveFolder); HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0]; var reponseMessage = ui.Save(file); return((reponseMessage).ModelToJson()); }
public JsonResult uploadFile() { UploadFile uf = new UploadFile(); uf.SetFileType("*"); string url = "/UpLoadFile/";//文件保存路径 string saveFolder = Server.MapPath(url); uf.SetFileDirectory(saveFolder); HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0]; string fileName = file.FileName; var reponseMessage = uf.Save(file, "VehicleRepairComplaints"); return(Json(new { Success = true, Data = new { FilePath = reponseMessage.WebFilePath, FileName = fileName } }, JsonRequestBehavior.AllowGet)); }
public JsonResult uploadFile(string user, Guid vguid, int number, string type) { UploadFile uf = new UploadFile(); uf.SetFileType("*"); string url = "/UpLoadFile/";//文件保存路径 string saveFolder = Server.MapPath(url); uf.SetFileDirectory(saveFolder); HttpPostedFile file = System.Web.HttpContext.Current.Request.Files[0]; string fileName = file.FileName; var reponseMessage = uf.Save(file, "RideCheckFeedback"); if (type == "invoice") { SaveRideCheckFeedbackItemInfor(user, vguid, 7, reponseMessage.WebFilePath, "", "", "", "", "", ""); } else { _logic.SaveBusiness_RideCheckFeedbackAttachment(user, vguid, fileName, reponseMessage.WebFilePath); } return(Json(new { Success = true, Data = new { FilePath = reponseMessage.WebFilePath, FileName = fileName } }, JsonRequestBehavior.AllowGet)); }