public ActionResult Upload(HttpPostedFileBase Filedata) { // 没有文件上传,直接返回 if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == 0) { return(HttpNotFound()); } //获取文件完整文件名(包含绝对路径) //文件存放路径格式:/files/upload/{日期}/{md5}.{后缀名} //例如:/files/upload/20130913/43CA215D947F8C1F1DDFCED383C4D706.jpg string fileMD5 = Md5.md5(Filedata.FileName, 16); string FileEextension = Path.GetExtension(Filedata.FileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string imgType = Request["imgType"]; string tablename = Request["tablename"]; //表名 string recordid = Request["recordid"]; //记录ID string virtualPath = "/"; if (imgType == "normal") { virtualPath = string.Format("~/files/upload/{0}/{1}{2}", uploadDate, fileMD5, FileEextension); } else { virtualPath = string.Format("~/files/upload2/{0}/{1}{2}", uploadDate, fileMD5, FileEextension); } string fullFileName = this.Server.MapPath(virtualPath); //创建文件夹,保存文件 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); if (!System.IO.File.Exists(fullFileName)) { Filedata.SaveAs(fullFileName); if (tablename != null && recordid != null) { //保存附件记录 WebAttachmentEntity attachmentEntity = new WebAttachmentEntity(); attachmentEntity.F_TableName = tablename; attachmentEntity.F_TableRecordID = recordid; attachmentEntity.F_FileSize = FileHelper.ToFileSize(FileHelper.GetFileSize(fullFileName)); attachmentEntity.F_FileType = FileHelper.GetExtension(fullFileName); attachmentEntity.F_FullName = FileHelper.GetFileName(fullFileName); attachmentEntity.F_FilePath = virtualPath; attachmentEntity.F_EnabledMark = true; new WebAttachmentApp().SubmitForm(attachmentEntity, ""); } } var data = new { imgtype = imgType, imgpath = virtualPath.Remove(0, 1) }; return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult DisabledConents(string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { WebAttachmentEntity attachmentEntity = new WebAttachmentEntity(); attachmentEntity.F_Id = keyValue; attachmentEntity.F_EnabledMark = false; attachmentApp.UpdateForm(attachmentEntity); return(Success("禁用成功")); } return(Success("请选择禁用项")); }
public void SubmitForm(WebAttachmentEntity entity, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); service.Update(entity); } else { entity.Create(); service.Insert(entity); } }
public ActionResult DeleteForm(string keyValue) { WebAttachmentEntity watt = attachmentApp.GetForm(keyValue); if (watt.F_FilePath.Length > 0) { string fullFileName = Server.MapPath(watt.F_FilePath); Thread t2 = new Thread(new ParameterizedThreadStart(DeleteFile)); t2.Start(fullFileName); } attachmentApp.DeleteForm(keyValue); return(Success("删除成功。")); }
public ActionResult SubmitForm(WebAttachmentEntity attachmentEntity, string keyValue) { if (!string.IsNullOrEmpty(attachmentEntity.F_FilePath)) { var path = Server.MapPath(attachmentEntity.F_FilePath); if (FileHelper.IsExistFile(path)) { attachmentEntity.F_FileSize = FileHelper.ToFileSize(FileHelper.GetFileSize(path)); attachmentEntity.F_FileType = FileHelper.GetExtension(path); if (string.IsNullOrEmpty(attachmentEntity.F_FullName)) { attachmentEntity.F_FullName = FileHelper.GetFileName(path); } } } attachmentApp.SubmitForm(attachmentEntity, keyValue); return(Success("操作成功。")); }
public void UpdateForm(WebAttachmentEntity entity) { service.Update(entity); }
public void Delete(WebAttachmentEntity entity) { service.Delete(entity); }