示例#1
0
        // GET: FilesUpload
        public ActionResult Index()
        {
            // Cargamos los archivos de una carpeta temporal
            List <FilesUploadViewModel> filesVM = new List <FilesUploadViewModel>();

            var files = Directory.GetFiles(@"C:\temp");

            foreach (string item in files)
            {
                FilesUploadViewModel fi = new FilesUploadViewModel();
                fi.FileName = Path.GetFileName(item);
                fi.FileSize = new FileInfo(item).Length;

                filesVM.Add(fi);
            }

            return(View("Index", filesVM));
        }
示例#2
0
        public ActionResult Upload(FilesUploadViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.File.ContentLength > UserFile.MAX_FILESIZE)
            {
                ViewBag.Error = "File size can not be bigger than 1 MB";
                return(View(model));
            }
            UserFile file = new UserFile(model.File);

            var userId = User.Identity.GetUserId();
            var user   = db.Users.Find(userId);

            user.Files.Add(file);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }