Esempio n. 1
0
 public bool DeleteFile(FileModel file)
 {
     bool result = false;
     try {
         if (file != null) {
             string rootPath = HttpContext.Current.Server.MapPath("~/");
             string fileName = Path.Combine(rootPath, file.FilePath, file.FileName);
             if (File.Exists(fileName)) {
                 File.Delete(fileName);
                 result = true;
             }
         }
     } catch { }
     return result;
 }
Esempio n. 2
0
 public static bool DeleteFile(FileModel file)
 {
     return _FileUpload.DeleteFile(file);
 }
Esempio n. 3
0
 public FileModel UploadFile(HttpPostedFile uploadFile, string appSettingName, params object[] args)
 {
     string rootPath = HttpContext.Current.Server.MapPath("~/");
     string uploadFilePath = Path.Combine(rootPath, string.Format(this.UploadPathKeys[appSettingName].Value, args));
     string directoryName = Path.GetDirectoryName(uploadFilePath);
     FileModel uploadFileModel = null;
     if (Directory.Exists(directoryName) == false) {
         Directory.CreateDirectory(directoryName);
     }
     if (File.Exists(uploadFilePath)) {
         File.Delete(uploadFilePath);
     }
     uploadFile.SaveAs(uploadFilePath);
     FileInfo fileInfo = new FileInfo(uploadFilePath);
     uploadFileModel = new FileModel {
         FileName = fileInfo.Name,
         FilePath = directoryName.Replace(rootPath, ""),
         Size = fileInfo.Length
     };
     return uploadFileModel;
 }