Beispiel #1
0
        public File UploadFile(HttpPostedFileBase postedFile, string tags = "", string uploadPath = "")
        {
            var rootPath   = HttpContext.Current.Server.MapPath("~/");
            var datePrefix = ParameterService.GetValueByKey("UploadFolderDatePrefix");
            var datePath   = DateTime.Now.ToString(datePrefix, CultureInfo.InvariantCulture);

            if (string.IsNullOrEmpty(uploadPath))
            {
                uploadPath = ParameterService.GetValueByKey("FileUploadFolder");
            }
            var    folderPath = Path.Combine(rootPath.Trim('\\'), uploadPath.Trim('\\'), datePath.Trim('\\'));
            string fullPath;

            Directory.CreateDirectory(folderPath);
            do
            {
                fullPath = Path.Combine(folderPath.Trim('\\'), GenarateFileName(postedFile.FileName).Trim('\\'));
            } while (System.IO.File.Exists(fullPath));

            postedFile.SaveAs(fullPath);
            var file = new File
            {
                Path         = "/" + fullPath.Replace(rootPath, "").Replace("\\", "/"),
                UploadedTime = DateTime.Now,
                Tags         = tags
            };

            Add(file);

            return(file);
        }
Beispiel #2
0
 public void Add(File item)
 {
     FileRepository.Add(item);
 }