public bool FileDelete(File file) { if (file == null) return true; if (System.IO.File.Exists(Server.MapPath(file.Url))) { System.IO.File.Delete(Server.MapPath(file.Url)); } return new FileRepository().Delete(file) != Enum.EntityResult.Failed; }
public bool FileDelete(File file) { if (file == null) { return(true); } if (System.IO.File.Exists(Server.MapPath(file.Url))) { System.IO.File.Delete(Server.MapPath(file.Url)); } return(new FileRepository().Delete(file) != Enum.EntityResult.Failed); }
public File FileSave(HttpPostedFileBase file, string folder, Enum.FileType fileType) { string newFullPath = ""; try { int count = 1; string fileNameOnly = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); var mappath = "~/Content/" + "Uploads/" + folder + "/"; newFullPath = Path.Combine(mappath + fileNameOnly + extension); if (!Directory.Exists(Server.MapPath(mappath))) { Directory.CreateDirectory(Server.MapPath(mappath)); } while (System.IO.File.Exists(Server.MapPath(newFullPath))) { string tempFileName = String.Format("{0}-{1}", fileNameOnly, count++); newFullPath = Path.Combine(mappath, tempFileName + extension); } file.SaveAs(Server.MapPath(newFullPath)); var uploadedFile = new File { Active = true, AuthorId = new AuthenticatedAuthor().Id, Extension = extension, FileType = fileType, FileName = fileNameOnly, Folder = folder, Url = newFullPath, UploadDateTime = DateTime.Now, Title = fileNameOnly }; return(new FileRepository().Create(uploadedFile) == Enum.EntityResult.Failed ? null : uploadedFile); } catch (Exception) { System.IO.File.Delete(Server.MapPath(newFullPath)); return(null); } }
public File FileSave(HttpPostedFileBase file, string folder, Enum.FileType fileType) { string newFullPath = ""; try { int count = 1; string fileNameOnly = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); var mappath = "~/Content/" + "Uploads/" + folder + "/"; newFullPath = Path.Combine(mappath + fileNameOnly + extension); if (!Directory.Exists(Server.MapPath(mappath))) { Directory.CreateDirectory(Server.MapPath(mappath)); } while (System.IO.File.Exists(Server.MapPath(newFullPath))) { string tempFileName = String.Format("{0}-{1}", fileNameOnly, count++); newFullPath = Path.Combine(mappath, tempFileName + extension); } file.SaveAs(Server.MapPath(newFullPath)); var uploadedFile = new File { Active = true, AuthorId = new AuthenticatedAuthor().Id, Extension = extension, FileType = fileType, FileName = fileNameOnly, Folder = folder, Url = newFullPath, UploadDateTime = DateTime.Now, Title = fileNameOnly }; return new FileRepository().Create(uploadedFile) == Enum.EntityResult.Failed ? null : uploadedFile; } catch (Exception) { System.IO.File.Delete(Server.MapPath(newFullPath)); return null; } }