Beispiel #1
0
        public static File SaveFile(HttpPostedFileBase file)
        {
            UnitOfWork context = new UnitOfWork(new KhMediumEntities());

            if (file == null)
            {
                return(null);
            }
            var fileName     = Path.GetFileName(file.FileName);
            var extension    = Path.GetExtension(fileName);
            var fileNamePath = Guid.NewGuid() + extension;
            var path         = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/FileUpload/"), fileNamePath);

            file.SaveAs(path);

            var dbFile = new File()
            {
                Id        = Guid.NewGuid().ToString(),
                Path      = fileNamePath,
                CreatedAt = DateTime.Now,
                UserId    = System.Web.HttpContext.Current.User.Identity.GetUserId()
            };

            context.Files.Add(dbFile);
            context.Complete();
            return(dbFile);
        }
Beispiel #2
0
 //File
 public static String FullPath(this File file)
 {
     return(Path.Combine(HttpContext.Current.Server.MapPath("~/FileUpload/"), file.Path));
 }