public ActionResult Load() { DirectoryInfo dir = new DirectoryInfo(Server.MapPath("/Content/autoadd")); DirectoryInfo target = new DirectoryInfo(Server.MapPath("/Content/Media/Img/PostFiesta")); FileInfo[] files = dir.GetFiles(); for (int i = 0; i < files.Count(); i++) { //CREATE IMAG OBJECT IMAG imag = new IMAG(); imag.ID = PostFiestaHelper.GetIMAGNextNumber(); imag.USERNAME = "******"; imag.VALID = "Y"; imag.LINK = Url.Content("/Content/Media/Img/PostFiesta/" + imag.ID + files[i].Extension ); //MOVE FILE TO TARGET string fileName = Server.MapPath("/Content/Media/Img/PostFiesta/") + imag.ID + files[i].Extension; files[i].MoveTo(fileName); ctx.IMAG.Add(imag); ctx.SaveChanges(); } ViewBag.fileAmount = files.Count(); return View(); }
public ActionResult Cargar(string Titulo, HttpPostedFileBase Foto) { IMAG imag = new IMAG(); imag.TITULO = Titulo; imag.USERNAME = ContextHelper.LoggedUser.USERNAME; imag.VALID = "Y"; imag.ID = PostFiestaHelper.GetIMAGNextNumber(); imag.LINK = Url.Content("/Content/Media/Img/PostFiesta/" + imag.ID + Foto.FileName.Substring(Foto.FileName.LastIndexOf("."))); string fileName = Server.MapPath(imag.LINK); Foto.SaveAs(fileName); ctx.IMAG.Add(imag); ctx.SaveChanges(); return RedirectToAction("Galeria", new { @ID = imag.ID.ToString() }); }