Hola amigos estoy tratando de guardar un archivo dentro de un carpeta que creo de forma dinámica, hasta aquí no hay problema, la cuestión es que cuando le intento pasar el file ya en mi método lo recibe como Null, ¿alguien podría decirme en donde estoy errando? Estoy obteniendo este error.
[HttpPost]
public void CreateFolder() {
if (Request.Files.Count > 0)
{
foreach (HttpPostedFile file in Request.Files)
{
Random rnd = new Random();
int rndx = rnd.Next(0, 1000);
string extension = System.IO.Path.GetExtension(file.FileName);
string fname = System.IO.Path.GetFileName(file.FileName);
string dt = DateTime.Now.ToString("M/d/yyyy");
var folder = Server.MapPath("~/Facturas/" + rndx);
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
string filePath = Path.Combine(Server.MapPath("~/Facturas/" + rndx)
, "" + rndx + "_" + dt + "_" + fname + "_" + extension);
file.SaveAs(filePath);
}
}
}
//end method
}
@using (Html.BeginForm("CreateFolder", "SAMAcceso", FormMethod.Post)) { @Html.TextBox("file","",new {type= "file" })
<input type="submit" value="cargar" /> }
Request.Files
?Request.Files
en ella, hazle un debug y nos comentas que te trae :)