示例#1
0
        /// <summary>
        /// Checking that the file is not null, its size is not zero and its extension is correct
        /// </summary>
        /// <param name="file">Sended file for check</param>
        /// <returns>Result of checing file</returns>
        private static UploadResult CheckFile(HttpPostedFileBase file)
        {
            if (file == null)
            {
                return(UploadResultFactory.MakeError("The file is empty."));
            }

            if (file.ContentLength <= 0)
            {
                return(UploadResultFactory.MakeError("The file size is zero."));
            }

            if (!IsWhiteExtention(TakeFileExtention(file)))
            {
                return(UploadResultFactory.MakeError("File format is not acceptable."));
            }

            return(UploadResultFactory.MakeSuccess());
        }
示例#2
0
 /// <summary>
 /// Save the file to destination
 /// </summary>
 /// <param name="file">file that you want to save it</param>
 /// <param name="destination">destination for save file</param>
 /// <returns>Result of file upload</returns>
 public static UploadResult Upload(HttpPostedFileBase file, string destination)
 {
     try
     {
         var result = CheckFile(file);
         if (result.Error)
         {
             return(result);
         }
         else
         {
             var savedFileName = SaveFile(file, destination);
             return(UploadResultFactory.MakeSuccess(savedFileName));
         }
     }
     catch (Exception ex)
     {
         return(UploadResultFactory.MakeError(ex.Message));
     }
 }