public JsonResult UploadPhoto() { HttpPostedFileBase uploadFiles0 = Request.Files["picUpload"]; if (uploadFiles0 != null && uploadFiles0.ContentLength > 0 && !string.IsNullOrEmpty(uploadFiles0.FileName)) { UpFileEntity fileEntity0 = new UpFileEntity() { Size = 2048 }; fileEntity0.Dir = "/VendorImages/"; fileEntity0.AllowType = ".jpg,.jpeg,.gif,.png,.bmp"; AttachmentInfo attch0 = UploadProvider.GetInstance("Common").UploadFile(uploadFiles0, fileEntity0); if (string.IsNullOrEmpty(attch0.Error)) { return(JsonMessage(true, attch0.FileName)); } else { return(JsonMessage(false, attch0.Error)); } } return(JsonMessage(false, "上传不成功...")); }
public ActionResult EditAvatar(FormCollection collection, HttpPostedFileBase File) { var id = collection["ID"].ToIntOrZero(); var myModel = _appUserService.GetById(id); var result = new JsonResultBO(true); try { if (File != null && File.ContentLength > 0) { var resultUpload = UploadProvider.SaveFile(File, null, ".jpg,.png", null, "images/avatars" + myModel.Id.ToString(), HostingEnvironment.MapPath("/assets")); if (resultUpload.status == true) { myModel.Avatar = resultUpload.path; } } _appUserService.Update(myModel); } catch { result.Status = false; result.Message = "Không cập nhật được"; } return(RedirectToAction("Detail", new { id })); }
/// <summary> /// 添加UEditor后端服务 /// </summary> /// <param name="services">IServiceCollection</param> /// <param name="configFileRelativePath">配置文件相对路径</param> /// <param name="isCacheConfig">是否缓存配置文件</param> /// <param name="basePath">配置文件、文件存储路径等各种路径的根目录,默认为Web项目的根目录</param> public static void AddUEditorServices(this IServiceCollection services, UploadProvider uploadProvider = UploadProvider.Physical, string configFileRelativePath = "ueditor.json", bool isCacheConfig = true, string contentRootPath = "", string webRootPath = "") { EditorConfig.ConfigFile = configFileRelativePath; EditorConfig.NoCache = isCacheConfig; EditorConfig.ContentRootPath = contentRootPath; EditorConfig.WebRootPath = webRootPath; services.TryAddSingleton <UEditorService>(); switch (uploadProvider) { case UploadProvider.Physical: services.AddScoped <IFileUploder, PhysicalFileUploder>(); break; case UploadProvider.Bos: services.AddScoped <IFileUploder, BosUploader>(); break; case UploadProvider.Qiniu: services.AddScoped <IFileUploder, QiniuUploader>(); break; default: break; } }
public ActionResult Index(string a) { if (ModelState.IsValid) { UpFileEntity fileEntity0 = new UpFileEntity() { Size = 2048 }; fileEntity0.Dir = "weixin/"; fileEntity0.AllowType = ".jpg,.jpeg,.gif,.png,.bmp"; UploadProvider.GetInstance().UploadFile(Request.Files["testfile"], fileEntity0); } return(View()); }
public JsonResult UploadBanner(string id) { try { HttpPostedFileBase uploadImage = Request.Files[0]; string imgFileName = String.Empty; //返回的图片路径 string imgErr = String.Empty; //返回的上传错误信息 if (uploadImage != null && uploadImage.ContentLength > 0) { IUpload upload = UploadProvider.GetInstance(); UpFileEntity fileEntity = new UpFileEntity() { Size = 4096, AllowType = ".jpg,.jpeg,.bmp,.gif,.png" }; fileEntity.Dir = "/Plugin/"; fileEntity.AllowType = ".jpg,.jpeg,.gif,.png,.bmp"; AttachmentInfo attch = upload.UploadFile(uploadImage, fileEntity); if (attch != null && string.IsNullOrEmpty(attch.Error)) { imgFileName = attch.FileName; } else { imgErr = attch.Error; } } else { imgErr = "请选择上传文件"; } var res = new JsonResult(); var person = new { err = imgErr, msg = imgFileName }; res.Data = person;//返回单个对象 res.ContentType = "application/javascript"; res.ContentEncoding = Encoding.UTF8; return(res); } catch (Exception ex) { throw new Exception("上传文件测试", ex); } }
public JsonResult Create(FormCollection collection, HttpPostedFileBase ICON) { AssignUserInfo(); WF_STEPBusiness = Get <WF_STEPBusiness>(); var result = new JsonResultBO(true); try { var myobj = new WF_STEP(); myobj.WF_ID = collection["WF_ID"].ToIntOrZero(); myobj.STATE_BEGIN = collection["STATE_BEGIN"].ToIntOrZero(); myobj.STATE_END = collection["STATE_END"].ToIntOrZero(); myobj.create_at = DateTime.Now; myobj.IS_RETURN = collection["IS_RETURN"].ToBoolByOnOff(); myobj.create_by = currentUser.ID; myobj.NAME = collection["NAME"].ToString(); myobj.GHICHU = collection["GHICHU"].ToString(); myobj.REQUIRED_REVIEW = collection["REQUIRED_REVIEW"].ToBoolByOnOff(); if (ICON != null) { var resultUpload = UploadProvider.SaveFile(ICON, null, ".jpg,.png,.jpeg", null, "IconWF", UPLOADFOLDER); if (resultUpload.status) { myobj.ICON = resultUpload.path; } else { result.Message = resultUpload.message; } } WF_STEPBusiness.Save(myobj); } catch { result.Status = false; result.Message = "Không thêm mới được"; } return(Json(result)); }
public JsonResultBO SaveTemplateFile(SaveFileModel saveFileModel, string category) { var result = new JsonResultBO(true); var saveRes = UploadProvider.SaveFile(saveFileModel.File, saveFileModel.Name.GetFileNameFormart(), saveFileModel.ExtensionList, saveFileModel.MaxSize, saveFileModel.Folder, saveFileModel.Path); if (saveRes.status) { var obj = new TD_QuanLyMauTest(); obj.FileDirectory = saveRes.path; obj.FileName = string.IsNullOrEmpty(saveFileModel.Name) ? saveFileModel.File.FileName : saveFileModel.Name; obj.Category = category; obj.Size = saveFileModel.File.ContentLength / 1024; _quanLyMauTestRepository.Add(obj); _quanLyMauTestRepository.Save(); } else { result.Status = false; result.Message = saveRes.message; } return(result); }
public JsonResultBO SaveMultiFile(string ITEM_TYPE, long ITEM_ID, List <HttpPostedFileBase> lstFile, List <string> NameFile, string AllowExtention, int?maxSize, string folder, string pathSave, long?userID) { var result = new JsonResultBO(true); for (int i = 0; i < lstFile.Count; i++) { if (lstFile[i] != null) { var resultSave = UploadProvider.SaveFile(lstFile[i], NameFile[i].GetFileNameFormart(), AllowExtention, maxSize, folder, pathSave); if (resultSave.status) { var obj = new TaiLieuDinhKem(); obj.TenTaiLieu = string.IsNullOrEmpty(NameFile[i]) ? lstFile[i].FileName : NameFile[i]; var arrName = lstFile[i].FileName.Split('.'); var extention = '.' + arrName[arrName.Length - 1]; obj.DinhDangFile = extention; obj.DuongDanFile = resultSave.path; obj.Item_ID = ITEM_ID; obj.LoaiTaiLieu = ITEM_TYPE; obj.NgayPhatHanh = DateTime.Now; obj.SoLuongDownload = 0; obj.UserId = userID; obj.KichThuoc = (lstFile[i].ContentLength / 1024); _taiLieuDinhKemRepository.Add(obj); _taiLieuDinhKemRepository.Save(); } else { result.Status = false; result.Message += "Tệp " + (i + 1) + " " + resultSave.message + "<br/>"; } } } return(result); }
public JsonResult CheckImport(int idNhomDanhMuc, HttpPostedFileBase fileImport) { JsonResultImportBO <DM_DANHMUC_DATA> result = new JsonResultImportBO <DM_DANHMUC_DATA>(true); DM_NHOMDANHMUCBusiness = Get <DM_NHOMDANHMUCBusiness>(); DM_DANHMUC_DATABusiness = Get <DM_DANHMUC_DATABusiness>(); //Kiểm tra file có tồn tại k? if (fileImport == null) { result.Status = false; result.Message = "Không có file đọc dữ liệu"; return(Json(result)); } //Lưu file upload để đọc var saveFileResult = UploadProvider.SaveFile(fileImport, null, ".xls,.xlsx", null, "TempImportFile", UPLOADFOLDER); if (!saveFileResult.status) { result.Status = false; result.Message = saveFileResult.message; return(Json(result)); } else { var importHelper = new ImportExcelHelper <DM_DANHMUC_DATA>(); importHelper.PathTemplate = saveFileResult.fullPath; importHelper.ConfigColumn = new List <ConfigModule>(); importHelper.ConfigColumn.Add(new ConfigModule() { columnName = "TEXT", require = true, TypeValue = typeof(string).FullName, }); importHelper.ConfigColumn.Add(new ConfigModule() { columnName = "DATA", require = true, TypeValue = typeof(int).FullName, }); //importHelper.ConfigColumn.Add(new ConfigModule() //{ // columnName = "DEPTID", // require = true, // TypeValue = typeof(int).FullName, //}); importHelper.ConfigColumn.Add(new ConfigModule() { columnName = "CODE", require = true, TypeValue = typeof(string).FullName, }); //importHelper.ConfigColumn.Add(new ConfigModule() //{ // columnName = "GHICHU", // require = true, // TypeValue = typeof(string).FullName, //}); //var configTang = new ConfigModule() //{ // columnName = "GHICHU", // require = false, // TypeValue = typeof(string).FullName, //}; var rsl = importHelper.Import(); if (rsl.Status) { result.Status = true; result.Message = rsl.Message; //foreach (var item in rsl.ListTrue.ToList()) //{ // var checkresult = DM_DANHMUC_DATABusiness.ExistValue(idNhomDanhMuc, item.DATA.GetValueOrDefault()); // if (checkresult.Status) // { // var listStrErr = new List<string>(); // listStrErr.Add("0"); // listStrErr.Add(item.TEXT); // listStrErr.Add(item.DATA.ToString()); // listStrErr.Add(item.DEPTID.ToString()); // listStrErr.Add(item.CODE.ToString()); // listStrErr.Add(item.GHICHU.ToString()); // listStrErr.Add("+ " + checkresult.Message); // rsl.lstFalse.Add(listStrErr); // rsl.ListTrue.Remove(item); // } //} result.ListData = rsl.ListTrue; result.ListFalse = rsl.lstFalse; } else { result.Status = false; result.Message = rsl.Message; } } return(Json(result)); }
public ActionResult Save(FormCollection collection, IEnumerable <HttpPostedFileBase> filebase) { AssignUserInfo(); qlXeBusiness = Get <QL_XEBusiness>(); JsonResultBO result = new JsonResultBO(true); try { var file = filebase.FirstOrDefault(); QL_XE xeEntity = new QL_XE(); xeEntity.TENXE = collection["TENXE"].Trim(); xeEntity.BIENSO = collection["BIENSO"].Trim(); xeEntity.SOCHO = collection["SOCHO"].ToIntOrZero(); xeEntity.GHICHU = collection["GHICHU"].Trim(); xeEntity.CCTC_THANHPHAN_ID = currentUser.DeptParentID.GetValueOrDefault(); xeEntity.NGUOISUA = currentUser.ID; xeEntity.NGAYSUA = DateTime.Now; int ID = collection["ID"].ToIntOrZero(); if (ID > 0) { QL_XE dbEntity = qlXeBusiness.Find(ID); if (dbEntity != null) { dbEntity.TENXE = xeEntity.TENXE; dbEntity.BIENSO = xeEntity.BIENSO; dbEntity.SOCHO = xeEntity.SOCHO; dbEntity.GHICHU = xeEntity.GHICHU; dbEntity.CCTC_THANHPHAN_ID = xeEntity.CCTC_THANHPHAN_ID; QL_XE existedCar = qlXeBusiness.context.QL_XE.Where(x => x.IS_DELETE != true && x.BIENSO == xeEntity.BIENSO && x.ID != dbEntity.ID) .FirstOrDefault(); if (existedCar != null) { TempData["EditMessage"] = "Biển số xe đã tồn tại"; TempData["Status"] = false; return(RedirectToAction("Index")); } else { existedCar = qlXeBusiness.context.QL_XE.Where(x => x.IS_DELETE != true && x.TENXE == xeEntity.TENXE && x.ID != dbEntity.ID) .FirstOrDefault(); if (existedCar != null) { TempData["EditMessage"] = "Tên xe đã tồn tại"; TempData["Status"] = false; return(RedirectToAction("Index")); } } qlXeBusiness.Save(dbEntity); if (file != null && file.ContentLength > 0) { var saveFileResult = UploadProvider.SaveFile(file, null, ".png,.gif,.jpeg,.jpg,.PNG,.GIF,.JPEG,.JPG", null, "CarImage\\" + dbEntity.ID, UPLOAD_PATH); if (saveFileResult.status) { dbEntity.IMAGE_PATH = saveFileResult.path; qlXeBusiness.Save(dbEntity); } } TempData["EditMessage"] = "Cập nhật xe thành công"; TempData["Status"] = true; } else { TempData["EditMessage"] = "Xe không tồn tại"; TempData["Status"] = false; } } else { QL_XE existedCar = qlXeBusiness.context.QL_XE.Where(x => x.IS_DELETE != true && x.BIENSO == xeEntity.BIENSO).FirstOrDefault(); if (existedCar != null) { TempData["EditMessage"] = "Biển số xe đã tồn tại"; TempData["Status"] = false; return(RedirectToAction("Index")); } else { existedCar = qlXeBusiness.context.QL_XE.Where(x => x.IS_DELETE != true && x.TENXE == xeEntity.TENXE) .FirstOrDefault(); if (existedCar != null) { TempData["EditMessage"] = "Tên xe đã tồn tại"; TempData["Status"] = false; return(RedirectToAction("Index")); } } xeEntity.NGUOITAO = currentUser.ID; xeEntity.NGAYSUA = DateTime.Now; qlXeBusiness.Save(xeEntity); if (file != null && file.ContentLength > 0) { var saveFileResult = UploadProvider.SaveFile(file, null, ".png,.gif,.jpeg,.jpg,.PNG,.GIF,.JPEG,.JPG", null, "CarImage\\" + xeEntity.ID, UPLOAD_PATH); if (saveFileResult.status) { xeEntity.IMAGE_PATH = saveFileResult.path; qlXeBusiness.Save(xeEntity); } } TempData["EditMessage"] = "Thêm mới xe thành công"; TempData["Status"] = true; } } catch (Exception ex) { TempData["EditMessage"] = ex.Message; TempData["Status"] = false; } return(RedirectToAction("Index")); }