Ejemplo n.º 1
0
        public IActionResult OnPost(IFormFile file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    Directory.CreateDirectory(Path.Combine(hostingEnvironment.WebRootPath, "images", Item.ItemName));
                    //HTML works with different kind of paths
                    Item.PicturePath = Path.Combine(Path.DirectorySeparatorChar.ToString(), "images", Item.ItemName, file.FileName);
                    using (var stream = new FileStream(Path.Combine(hostingEnvironment.WebRootPath, "images", Item.ItemName, file.FileName), FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                }

                dataAcces.UpdateItem(Item);
                return(RedirectToPage("/Details", new { id = Item.EncryptedId }));
            }
            else
            {
                return(RedirectToPage("Error"));
            }
        }